javaclassinheritancesubclass

Which members are not inherited in a child class?


I'm trying to answer the following question:

A child class would not inherit certain members of the parent class. Name three such members.

I know private members are not inherited to child classes and default members are not inherited outside of the package. Can anyone complete the answer?

Edited:- I believe that static members are inherited according to below demonstration

public class sup {
    public static void main(String agr[]){
    }

    protected static int staticInt=0;
    protected final int finalInt=3;
    protected int protectedInt=0;
    public String publicString = "";
    private int privateInt=8;
}

class sub extends sup{
    public void del(){
        staticInt=1;
        staticInt=finalInt;
    }
}

Solution

  • None-Answer to make a case for terms usage.

    Members which are visible in the child class is answered above. Members being both fields and methods (each having its own namespace).

    Inheritance as being part of the child instance, is another question: also invisible private members are "inherited" as such. Static members are part of the class instance and are not inherited (cannot be overriden too). All final methods cannot be overriden.

    Arguable constructors are not inherited; you have to define the same signature again in a new child constructor.

    Other declarations in a class could be class definitions. There the keyword static has a different meaning, and one may make obvious statements on visibility/inheritance. For instance with respect to non-static inner classes, which have an <outer-class>.this (recursive notion).