Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package multilevelinheritance;
- class Student
- {
- int Roll ;
- String Name = new String();
- void GetData(){
- Roll = 101;
- Name = "alim";
- }
- void Display()
- {
- System.out.println("inside Student class....");
- System.out.println("Roll is : "+ Roll);
- System.out.println("Name is : "+Name);
- }
- }
- class bro extends Student
- {
- int value ;
- void GetData()
- {
- value = 32;
- }
- void Display()
- {
- System.out.println("inside the bro....");
- System.out.println(value);
- }
- }
- class Exam extends bro{
- float Mark;
- void GetData()
- {
- Mark = 32.3f;
- }
- void Display()
- {
- System.out.println("Inside Exam class ...");
- System.out.println("Mark is : "+Mark);
- }
- }
- class Result extends Student
- {
- Student S = new Student();
- Exam E = new Exam();
- bro F = new bro();
- void GetData()
- {
- S.GetData();
- E.GetData();
- F.GetData();
- }
- void Dispaly()
- {
- S.Display();
- E.Display();
- F.Display();
- }
- }
- public class MultiLevelInheritance {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Result R = new Result();
- R.GetData();
- R.Dispaly();
- R.GetData();
- R.Display();
- R.GetData();
- R.Display();
- }
- }
- /*
- output
- inside Student class....
- Roll is : 101
- Name is : alim
- Inside Exam class ...
- Mark is : 32.3
- inside the bro....
- 32
- inside Student class....
- Roll is : 0
- Name is :
- inside Student class....
- Roll is : 0
- Name is :
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement