Public, Private, Protected, Default and Final variables and methods.
package Main;
package Main;
public class Car {
public static int a;
private static int b;
protected static int c;
static int d;
int e;
public int f;
public static int getB() {
return b;
}
public static void setB(int b) {
Car.b = b;
}
public static void foo1() {
}
public void foo2() {
}
private static void foo3() {
}
private void foo4() {
}
void foo5() {
}
public void foo6(){
}
}
package Another;
import Main.Car;
public class BMW extends Car {
}1. a : BMW.a and Car.a;2. b : BMW.getB() and Car.getB();3. c : BMW.c and Car.c;4. d : Car.d; BMW.d; But in an another package it is impossible to call them.5. e : Car c = new Car(); c.e. BMW b = new BMW(); b.e; But in another package it isimpossible to call them.6. f : Car c = new Car(); BMW b = new BMW(); c.f and b.f;7. foo1 : Car.foo1(); and BMW.foo1();8. foo2 : c.foo2(): and b.foo2();9. foo3 : this method only could be used inside class Car.10. foo4 : this method as well could be used inside class Car.11. foo5 : c.foo5(); b.foo5(); Outside the package it is impossible to use.12. foo6 : c.foo6(): and b.foo6();I guess this is clearer now.*Final keyword. Final variable has to be initialized. Final method can not beoverrrided. Final class can not be extended.
Комментарии
Отправить комментарий