I did not understand the part where you say "static means that method is not a part of the class"
And moreover If I do
- class B{
-
public static void out () {}
-
}
-
class D extends B {
-
public static void out() {}
-
}
-
class I{
-
public static void main(String[] argv) {
-
B obj = new D();
-
obj.out; //out of B is called but if u do something like
-
-
D obj1 = new D();
-
obj1.out; //out of D is called
-
}
-
Is it not supposed that all the functions of java are kind of virtual functions?
A static method is independent of the design of the class eg the main method inside any class has nothing to do with the design of that class. That is why you do not need to create objects to be able to call static methods. eg for your code above, obj.out can be (more appropriately) replaced by B.out.
That is why out of B is called when you do
- B obj = new D();
-
obj.out;
. B obj says that obj is a B. Any static calls on obj call methods in class B.
about that virtual function thing, I can only say that sometimes it is dangerous to carry over constructs of one language into another.