I was reading A Programmer’s Guide to Java™ SCJP Certification by Khalid Mughal.
In the Inheritance chapter, it explains that
Inheritance of members is closely tied to their declared accessibility. If a superclass member is accessible by its simple name in the subclass (without the use of any extra syntax like super), that member is considered inherited
It also mentions that static methods are not inherited. But the code below is perfectlly fine:
class A
{
public static void display()
{
System.out.println("Inside static method of superclass");
}
}
class B extends A
{
public void show()
{
// This works - accessing display() by its simple name -
// meaning it is inherited according to the book.
display();
}
}
How am I able to directly use display()
in class B
? Even more, B.display()
also works.
Does the book's explanation only apply to instance methods?