Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package multilevelinheritance;
  7. class Student
  8. {
  9. int Roll ;
  10. String Name = new String();
  11. void GetData(){
  12.  
  13. Roll = 101;
  14. Name = "alim";
  15. }
  16. void Display()
  17. {
  18. System.out.println("inside Student class....");
  19. System.out.println("Roll is : "+ Roll);
  20. System.out.println("Name is : "+Name);
  21. }
  22. }
  23. class bro extends Student
  24. {
  25. int value ;
  26.  
  27. void GetData()
  28. {
  29. value = 32;
  30. }
  31. void Display()
  32. {
  33. System.out.println("inside the bro....");
  34. System.out.println(value);
  35. }
  36. }
  37. class Exam extends bro{
  38.  
  39. float Mark;
  40. void GetData()
  41. {
  42.  
  43. Mark = 32.3f;
  44. }
  45. void Display()
  46. {
  47.  
  48. System.out.println("Inside Exam class ...");
  49. System.out.println("Mark is : "+Mark);
  50.  
  51. }
  52.  
  53. }
  54. class Result extends Student
  55. {
  56. Student S = new Student();
  57. Exam E = new Exam();
  58. bro F = new bro();
  59. void GetData()
  60. {
  61. S.GetData();
  62. E.GetData();
  63. F.GetData();
  64.  
  65. }
  66. void Dispaly()
  67. {
  68. S.Display();
  69. E.Display();
  70. F.Display();
  71. }
  72. }
  73.  
  74.  
  75.  
  76. public class MultiLevelInheritance {
  77.  
  78. /**
  79. * @param args the command line arguments
  80. */
  81. public static void main(String[] args) {
  82.  
  83. Result R = new Result();
  84.  
  85.  
  86. R.GetData();
  87. R.Dispaly();
  88. R.GetData();
  89. R.Display();
  90. R.GetData();
  91. R.Display();
  92.  
  93. }
  94.  
  95. }
  96. /*
  97. output
  98.  
  99. inside Student class....
  100. Roll is : 101
  101. Name is : alim
  102. Inside Exam class ...
  103. Mark is : 32.3
  104. inside the bro....
  105. 32
  106. inside Student class....
  107. Roll is : 0
  108. Name is :
  109. inside Student class....
  110. Roll is : 0
  111. Name is :
  112. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement