一个简单的继承

package test;
class father{
    int x;
    int y;
    father()
    {
        x=0;
        y=0;
    }
    void put()
    {
        System.out.println("I am father");
    }
    
}
class son extends father
{
    int x;
    int y;
    son()
    {
        x=1;
        y=1;
    }
    void put()
    {
        System.out.println("I am son");
    }
}
public class Main {
   public static void main(String args[])
   {
       father fa=new father();
       son so=new son();
       fa.put();
       so.put();
   }
}

   

I am father
I am son

原文地址:https://www.cnblogs.com/cs1003/p/2852076.html