public class ExtendsTest {     /**      * 继承关系测试      */     public static void main(String[] args) {         Student st=new Student("zhangSan",18);//实例化父类对象         st.show();//利用对象调用方法         Undergraduate ug=new Undergraduate("liSi",20,"undergraduate");         ug.show();     }

}
/*
 * 定义学生类
 * 属性:姓名 年龄 
 * 方法:输出属性
 */
class Student{        String name;      int age;     public Student(String name,int age){         this.name=name;         this.age=age;     }     public void show(){         System.out.println("姓名:"+name+" 年龄:"+age);     }
}
/*
 * 定义本科生子类
 * 增加新属性:专业
 */
class Undergraduate extends Student{     String degree=null;     public Undergraduate(String name,int age, String degree){         super(name,age);//调用父类构造函数         this.degree=degree;     }     public void show(){         System.out.println("姓名:"+name+" 年龄:"+age+" 专业:"+degree);     }
}