Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Java example for inheritance with protected data member

class Papa{
    protected int x;
    Papa(){ x=40;}
    Papa(int y){x=y;}
}
public class son extends Papa
{
    protected int x=0;
    son(){super(15);}
    son(int x){ }
         public static void main(String []args)
         {
                son s = new son();
                System.out.println(s.x+" ");
                Papa t =new son(2);
                System.out.println(t.x);
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.