Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. package p1;
  2. class classMaster
  3. {
  4. int a, b;
  5. String str;
  6. classMaster(int a , int b , String str)
  7. {
  8. this.a = a;
  9. this.b = b;
  10. this.str = str;
  11. }
  12.  
  13. void useValues()
  14. {
  15. System.out.println(str + " " + (a + b));
  16. }
  17. }
  18. class classMid extends classMaster
  19. {
  20. classMid(int a , int b , String str)
  21. {
  22. super(a,b,str);
  23. }
  24. void useValues()
  25. {
  26. System.out.println(str + " " + a / b);
  27. }
  28. }
  29. class classBot extends classMid
  30. {
  31. classBot(int a , int b , String str)
  32. {
  33. super(a,b,str);
  34. }
  35. void useValues()
  36. {
  37. System.out.println(str + " " + a * b);
  38. }
  39. }
  40.  
  41. public class useSuper {
  42.  
  43.  
  44. public static void main(String[] args) {
  45.  
  46. classMaster clsmstr;
  47.  
  48. classBot clsbt = new classBot(5 , 5 , "classBot");
  49. clsmstr = clsbt;
  50. clsmstr.useValues();
  51.  
  52. classMid clsmd = new classMid(5,5,"classMid");
  53. clsmstr = clsmd;
  54. clsmstr.useValues();
  55.  
  56. classMaster clsmtr = new classMaster(5,5,"classMaster");
  57. clsmstr = clsmtr;
  58. clsmstr.useValues();
  59.  
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement