package com.company;
public class Main {
public static void main(String[] args) {
Iddrivingtest drivingtest= new Drivingtest(new BMW());
}
}
interface Auto {
void drive();
}
public class BMW implements Auto{
Auto sam1;
BMW sam2;
@Override
public void drive() {
System.out.println("bmw drive");
}
}
public interface Iddrivingtest {
void test();
}
public class Drivingtest implements Iddrivingtest {
private Auto auto;
public Drivingtest(Auto auto)
{
this.auto=auto;
}
@Override
public void test() {
auto.drive();
}
}
Właśnie oglądam poradnik na temat javy i nie rozumiem paru rzeczy.
1.W klasie Drivingtest jest pole private Auto auto;
Auto to typ, a auto to klasa?? Czemu nie jest to zdefiniowane w taki sposób
Auto auto= new Auto;
2.W klasie Drivingtest, metodzie test pole: auto.drive(); Czemu auto może wykonać metode skoro nie ma
Auto auto= new Auto;
3.W klasie Main czemu jest akurat tak:
Iddrivingtest drivingtest= new Drivingtest(new BMW());
a nie np tak, czym to sie różni. Jakie ma znaczenie to że typem bedzie raz Interfejs, a raz klasa która implementuje dany interfejs?:
Drivingtest drivingtest = new Drivingtest(new BMW());