Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need explained answers to following questions with at least 4 sentences for ea

ID: 3662419 • Letter: I

Question

I need explained answers to following questions with at least 4 sentences for each

1)Describe and define two classes that would correctly model an inheritance relationship. Make sure to describe both the base class and the derived class, and discuss what the derived class inherits from the base class and why you designed the two classes in that manner.

2)What is the syntax of the Inheritance method to extending a base class ?

3)How would you instantiate an instance of the derive class, and call its base and derived methods ?

4)How would you use inheritance in an object-oriented program? You can use the example you provided in the Implementing Inheritance thread as a reference. Discuss when a program might use both the base class and the derived class and why.

Explanation / Answer

1) Ans.

2)Ans.

Result :

TheTest getI was used

MainOne says that I is 10.

MainOne getI was used

TheTest says that I is 5

Explanation:

This is all about order of execution and constructor inheritance. TheTest constructor implicitly calls the super MainOne constructor.

so

calls

which calls the overriden getI() because of polymorphism.

The i here is the static i declared in TheTest. Finally

gets called which uses MainOne's i.

You therefore get

3) Ans.

This is all about order of execution and constructor inheritance. TheTest constructor implicitly calls the super MainOne constructor.

so

  public TheTest() {      System.out.println("TheTest says that I is " + super.getI());  }  

calls

  public MainOne() {      System.out.println("MainOne says that I is " + getI());  }  

which calls the overriden getI() because of polymorphism.

  public int getI() {      System.out.println("TheTest getI was used");      return i;  }  

The i here is the static i declared in TheTest. Finally

  super.getI());  

gets called which uses MainOne's i.

You therefore get

  TheTest getI was used    MainOne says that I is 10.    MainOne getI was used    TheTest says that I is 5  

3) Ans.

  Class A  {     public void methodA()     {       System.out.println("Base class method");     }  }    Class B extends A  {     public void methodB()     {       System.out.println("Child class method");     }     public static void main(String args[])     {       B obj = new B();//instantiate an instance of the derive class        obj.methodA(); //calling super class method using derived class object.       obj.methodB(); //calling local method    }  }  
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote