Question

The UML diagram bellow shows an example for simple chain of inheritance relationship where ClassC inherits...

The UML diagram bellow shows an example for simple chain of inheritance relationship where ClassC inherits ClassB’s members, including the ones that ClassB inherited from ClassA. ClassA constructor has a println statement that prints "Hello This is ClassA", ClassB constructor has a println statement that prints "Hello this is ClassB" and ClassC constructor has a println statement that prints "Hello this is ClassC". ClassC is the driver class. If you create an object of ClassC,you will get the following output: Hello this is ClassA Hello this is ClassB Hello this is ClassC Now write a Java program that meets above conditions.

Homework Answers

Answer #1

Program:

//Program to be saved as ClassC.java

//classA
class ClassA
{
   //constructor of ClassA
   public ClassA()
   {
       //println statement in the constructor
       System.out.println("Hello this is ClassA");
   }
}

//classB that extends classA
class ClassB extends ClassA
{
   //constructor of ClassB
   public ClassB()
   {
       //println statement in the constructor
       System.out.println("Hello this is ClassB");
   }
}

////classC that extends classB, this our driver class also
public class ClassC extends ClassB
{
   //constructor of ClassC
   public ClassC()
   {
       //println statement in the constructor
       System.out.println("Hello this is ClassC");
   }
  
   //driver program
   public static void main(String[] args)
   {
       //create an object for classC
       ClassC obj=new ClassC();
       //creating an object for ClassC calls the constructors of the parent class
       //along with its own constructor and prints all the statements
   }

}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...