I was going through the sample questions of Java 8 Programmer I exam on Oracle website and came across the following question:
abstract class Writer {
public static void write() {
System.out.println("Writing...");
}
}
class Author extends Writer {
public static void write() {
System.out.println("Writing book");
}
}
class Programmer extends Writer {
public static void write() {
System.out.println("Writing code");
}
public static void main(String[] args) {
Writer w = new Author();
w.write();//What would be the ouput here?
}
}
The correct answer is that the method of the abstract class is called.
Now, my understanding was that in polymorphism, if a variable of type parent class contains a reference to an object of subclass, then the method of the subclass will be called.
Therefore, am I understanding right that in case of a static function, the method of the of the class whose variable contains the refrence would be called?