In object-oriented paradigm, a virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a f
Suppose you have class A
public class A
{
public static void doAStaticThing()
{
System.out.println("In class A");
}
}
And B
public class B extends A
{
public static void doAStaticThing()
{
System.out.println("In class B");
}
}
And a method in another class like this:
public void foo()
{
B aB = new B();
bar(B);
}
public void bar(A anA)
{
anA.doAStaticThing(); // gives a warning in Eclipse
}
The message you will see on the console is
In class A
The compiler has looked at the declared type of anA
in method bar and statically bound to class A's implementation of doAStaticThing()
. The method is not virtual.