Wednesday, 23 May 2018

                                                   Inheritance & interface Concept 


package javaresearch;

public interface DisplayData {
           
             void display_student_info();

}


package javaresearch;

public class Student implements DisplayData {
            String name;
    int age;
    String programme;
   public Student()
   {
              
   }
            public Student(String name, int age, String programme) {
                        super();
                        this.name = name;
                        this.age = age;
                        this.programme = programme;
            }
            @Override
            public void display_student_info() {
                        System.out.println("Name="+name+" "+"Age="+age+" "+"Programme="+programme);
                       
            }
   
   
   

}









package javaresearch;

public class GraduateStudent extends Student  {
           
           
            String streams;
            float m_per;
            public GraduateStudent(String name, int age, String programme, String streams, float m_per) {
                        super(name, age, programme);
                        this.streams = streams;
                        this.m_per = m_per;
            }
            @Override
           
            public void display_student_info() {
                        super.display_student_info();
                        System.out.println("Streams="+streams+" "+"Percentage="+m_per);
                       
            }
           
           

}


package javaresearch;

public class ResearchStudent extends Student  {
 String specialization;
 float expyrs;
public ResearchStudent(String name, int age, String programme, String specialization,float expyrs) {
            super(name, age, programme);
            this.specialization = specialization;
            this.expyrs = expyrs;
}
 @Override
public void display_student_info() {
             super.display_student_info();
            System.out.println("Specialization="+specialization+" "+"Experiance="+expyrs+”yrs”);
           
}
 }



package javaresearch;

public class MainStrudent {
            public static void main(String[] args) {
                        Student s1=new Student();
                GraduateStudent gs1=new GraduateStudent("govind", 26, "cse","science", 74.9f);
                GraduateStudent gs2=new GraduateStudent("geeta", 22, "cse","science", 79.9f);
                ResearchStudent rs1=new ResearchStudent("sachin", 27, "Electrical","power system",2.6f);
                ResearchStudent rs2=new ResearchStudent("sonali", 29, "cse","software engineering", 5.5f);
                System.out.println("-----------Graduate Student Information------");
                gs1.display_student_info();
                gs2.display_student_info();
                System.out.println("-----------Research Student Information------");
                        rs1.display_student_info();
                rs2.display_student_info();
               
               
        
       
     }

}



o/p view:--------------

-----------Graduate Student Information------
Name=govind Age=26 Programme=cse
Streams=science Percentage=74.9
Name=geeta Age=22 Programme=cse
Streams=science Percentage=79.9
-----------Research Student Information------
Name=sachin Age=27 Programme=Electrical
Specialization=power system Experiance=2.6 yrs
Name=sonali Age=29 Programme=cse
Specialization=software engineering Experiance=5.5 yrs




No comments:

Post a Comment