集册 Java实例教程 创建学生班以扩展人员班

创建学生班以扩展人员班

欢马劈雪     最近更新时间:2020-01-02 10:19:05

448
创建学生班以扩展人员班

class Person

{

    private String name;
    /*
    nowjava - 时代Java 提 供
    */

    private long phno;


    public void read()

    {

        name = "Akash";

        phno = 928374993;

    }


    public void show()

    {

        System.out.println("Name = " + name);

        System.out.println("Phone = " + phno);

    }/**n o w j a v a . c o m - 时代Java**/

}


class Student extends Person

{

    private int rollno;

    private String course;


    public void read()

    {

        super.read();

        rollno = 007;

        course = "Computer Science";

    }


    public void show()

    {

        super.show();

        System.out.println("Roll No. = " + rollno);

        System.out.println("Course = " + course);

    }

}


class Teacher extends Person

{


    private String dept_name;

    private String qual;


    public void read()

    {

        super.read();

        dept_name = "CSE";

        qual = "PhD";

    }


    public void show()

    {

        super.show();

        System.out.println("Departement = " + dept_name);

        System.out.println("Qualififcation = " + qual);

    }

}


class Hierarchical

{


    public static void main(String args[])

    {

        Student s1 = new Student
展开阅读全文