Header Ads

Header ADS

example:2:inheritance

  class college{

    String name;
    public college(String name){
        this.name=name;
    }
    public void student(){
        System.out.println("student learn in college");
    }
}
//child class
class Cr extends college{
    public Cr(String name){
        super(name);
    }
    public void student(){
        System.out.println(name + " is student of college");
    }

}
class teacher extends college {
    public teacher(String name) {
        super(name);
    }

    @Override
    public void student() {
        System.out.println(name + " is class teacher of saket college");
    }
}

public class firstprogramm {
    public static void main(String[] args) {
        Cr cr = new Cr("kuldeep");
        cr.student();

        teacher teacher= new teacher("shneha mam");
        teacher.student();
    }
}





No comments

Powered by Blogger.