Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. class myClass {
  2. public static void main(String[] args) {
  3. // create an object of the Student class (which inherits attributes and methods from Person)
  4. Student myObj = new Student();
  5.  
  6. System.out.println("Name: " + myObj.fname + " " + myObj.lname);
  7. System.out.println("Email: " + myObj.email);
  8. System.out.println("Age: " + myObj.age);
  9. System.out.println("Graduation Year: " + myObj.graduationYear);
  10. myObj.study(); // call abstract method
  11. }
  12. }
  13.  
  14. // abstract class
  15. abstract class Person {
  16. public String fname = "John";
  17. public String lname = "Doe";
  18. public String email = "john@doe.com";
  19. public int age = 24;
  20. public abstract void study(); // abstract method
  21. }
  22.  
  23. // Subclass (inherit from Person)
  24. class Student extends Person {
  25. public int graduationYear = 2018;
  26. public void study() {
  27. System.out.println("Studying all day long");
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement