Answer to Question #273811 in Java | JSP | JSF for babe

Question #273811

(Using Inheritance)


Create a parent class named “Parent”, with a method that displays “I am a Parent Class”.

Also create a subclass that named “Child” that has a method that prints “I am a Child Class”.


Now create a class with Main Method, where you will:

 Create an object for each class (1 for “Parent” and 1 for “Child”)

 Call the method of “Child” class by using the Child object

 Call the method of “Parent” class by object of the “Parent” class


1
Expert's answer
2021-11-30T18:39:45-0500


package parent;


public class Parent {


    
    public void print(){
        System.out.println("I am a Parent Class");
    }
    
    public static void main(String[] args) {
        Parent pa = new Parent();
        Child ch = new Child();
        pa.print();
        ch.display();
    }
    
}


class Child extends Parent{
    public void display(){
        System.out.println("I am a Child Class");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS