Advertisement
vvccs

E8_Parent/Child

Nov 8th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. class ParentClass {
  2.     public void parentMethod() {
  3.         System.out.println("This is parent class");
  4.     }
  5. }
  6.  
  7. class ChildClass extends ParentClass {
  8.     public void childMethod() {
  9.         System.out.println("This is child class");
  10.     }
  11. }
  12.  
  13. public class Main {
  14.     public static void main(String[] args) {
  15.         ParentClass parentObject = new ParentClass();
  16.        
  17.         ChildClass childObject = new ChildClass();
  18.        
  19.        
  20.         parentObject.parentMethod();
  21.        
  22.        
  23.         childObject.childMethod();
  24.         childObject.parentMethod();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement