Yes, Static members are also inherited to sub classes in java.
package com.w3spoint; class A{ static int num = 20; static void method() { System.out.println("Static Method"); } } class B extends A{ } public class Test { public static void main(String args[]){ //Calling inherited static method B.method(); //printing inherited static field. System.out.println(B.num); } } |
Output
Static Method 20 |
Java interview questions on Inheritance
- Why multiple inheritance is not supported in java?
- How to implement multiple inheritance in java?
- Are interfaces also inherited from Object class?
- Why an interface cannot have constructor in java?
- How do you restrict a member of a class from inheriting to it’s sub classes?
- Can a class extend itself in java?
- Are constructors inherited in java?
- What happens if both superclass and subclass have a field with same name?
- Are static members inherited to subclasses in java?
Please follow and like us: