Advertisement
Sajib_Ahmed

Untitled

Mar 2nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1.  
  2. package javaapplication10;
  3.  
  4.  
  5. public abstract class Person {
  6.  
  7. protected String name;
  8. protected String phone;
  9.  
  10. public Person(String name, String phone) {
  11. this.name = name;
  12. this.phone = phone;
  13. }
  14.  
  15. public void display()
  16. {
  17. System.out.println("Name : "+name+"\nPhone Number :"+phone);
  18. }
  19. }
  20.  
  21. package javaapplication10;
  22.  
  23.  
  24. public class Address {
  25. private String city;
  26. private String country;
  27.  
  28. public Address(String city, String country) {
  29. this.city = city;
  30. this.country = country;
  31. }
  32. public void display()
  33. {
  34. System.out.println("City :"+city+"\nCountry: "+country);
  35. }
  36. }
  37.  
  38. package javaapplication10;
  39.  
  40.  
  41. public class Main {
  42. public static void main(String[] args)
  43. {
  44. Student obj=new Student("CSE",3.64);
  45. obj.display();
  46. Address ob1=new Address("Dhaka","Bangladesh");
  47. ob1.display();
  48. Teacher obj2=new Teacher("Professor");
  49. obj2.display();
  50. Address ob4=new Address("Tangail","Bangladesh");
  51. ob4.display();
  52.  
  53.  
  54. }
  55.  
  56. }
  57.  
  58. package javaapplication10;
  59.  
  60.  
  61. public class Student extends Person {
  62. private String studid;
  63. private double cgpa;
  64.  
  65. public Student(String s, double c) {
  66. super("Ahmed", "0179");
  67. this.studid = s;
  68. this.cgpa = c;
  69. System.out.println("Student Information: ");
  70. System.out.println("Studied: "+s);
  71. System.out.println("CGPA: "+c);
  72. }
  73.  
  74.  
  75.  
  76.  
  77. }
  78.  
  79. package javaapplication10;
  80.  
  81.  
  82. public class Teacher extends Person {
  83. private String designation;
  84.  
  85. public Teacher(String d) {
  86. super("Shanto","01790363394");
  87. designation = d;
  88. System.out.println("Teacher Information: ");
  89. System.out.println("Designation: "+d);
  90. }
  91.  
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement