And static methods don't inherited.
Static methods are inherited. Take a look at jls-8.4.8 Inheritance, Overriding, and Hiding
A class C inherits from its direct superclass and direct superinterfaces all
abstract
andnon-abstract
methods of the superclass and superinterfaces that arepublic
,protected
, or declared withdefault
access in the same package as C, and are neither overridden (§8.4.8.1) nor hidden (§8.4.8.2) by a declaration in the class.
There is no information about not inheriting static methods, which is why you can run main
declared in Test1
via Test2
class (it was inherited).
Also from jls-8.4.8.2 Hiding (by Class Methods)
If a class declares a
static
methodm
, then the declarationm
is said to hide any methodm
', where the signature ofm
is a subsignature (§8.4.2) of the signature ofm
', in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class.
So when you created new main
method in Test2
class you hidden (not overridden) Test1.main
method which is why you saw as output
Test2