Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.1 kB
2
Indexable
Never
package com.company;

abstract class Person{

    public String name;
    public int age;

    Person(String name, int age){
        this.age=age;
        this.name=name;
    }
    abstract void typeofPerson();


}

class Student extends Person{

    private double cgpa;
    private int id;

    Student(String name, int age, double cgpa, int id) {
        super(name, age);
        this.cgpa=cgpa;
        this.id=id;
    }

    @Override
    void typeofPerson() {
        System.out.println("This is a Student class");
    }
}
class Teacher extends Person{

    private double salary;

    Teacher(String name, int age, double salary) {
        super(name, age);
        this.salary=salary;
    }

    @Override
    void typeofPerson() {
        System.out.println("This is a Teacher Class");
    }

}

class TestAbstraction1{
    public static void main(String args[]){
        Person s=new Student("Niaz", 22, 3.5, 123);
        Person t = new Teacher("kamal", 38, 40000.50);
        s.typeofPerson();
        t.typeofPerson();
    }
}