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

CSE 230 Homework 1. point) What is the core idea behind inheritance? 2. (I point

ID: 3818523 • Letter: C

Question

CSE 230 Homework 1. point) What is the core idea behind inheritance? 2. (I point) How would we indicate that the class Frigate is a child of the class Starship? (2 points) What does a child inherit from its parent? What does it not inherit? 4. (2 points) May a class have multiple children? Multiple parents? 5. (3 points) Consider the following class definitioas: class A public void fooo0 class B extends A public void baro class C extends B public void bazo Which methods may be called on an object of type C? 6. (2 points) Consider the following class definitions: class Dog public void speak o Sytem out.println("voof"): class Chihuahua public void speako Sytes out-println yipyipyip!"): What output is produced by the following code? Dog d new ChihuahuaO d speak 7. point) Why do we typically use super O? 8. (2 points) Why might a class override a method in its parent class? 9, point) Under what circumstances may a parent class call methods in a child ohject? 11. (2 points) What may access a protected data member?

Explanation / Answer

==================================================
1. Answer

  
  The idea behind inheritance is acuaring parent properties to
child properties such as fields and methods can be used in the later
classes. Which results reusability of code.
  

==================================================
2. Answer

  class Frigate is child of Starship can be determined by
using the extends keyword.

  If the class Frigate extends Starship means
Frigate is child of Starship

==================================================
3. Answer

  Child inherit from parent all the protected and public
properties and methods from parent class.

  Only private properties and methods can not be inherited
by child class since private scope is within the class.

==================================================
4. Answer


  A class can of multiple childs.
But a class can not extends multiple parents due to diamond
problem which leads to ambiguity.

==================================================
5. Answer

  In the given code snippet
  
class C extends B which extnds A

Created of object C, can access the method of class C and B, A

In this case objet of C can access foo(), bar(), baz() methods.

==================================================
6. Answer


  First of all the given code throws an error
Since there is no relation between Dog class and Chihuahua class.

We can not assign Chihuashua class to Dog class

==================================================
7. Answer


super() keyword is used to call parent class constructor.

==================================================
8. Answer


A class may overide a method in parent class, because sometimes
child class needs its own defination of same method signature.
In those cases it is required to override the method from parent class.
==================================================
9. Answer

Parent class can call the methods of child class , provided that
child class overrided the method which is present in the parent class.
This mechanism is called polymorphism.

==================================================
10. Answer


We need an abstract class, because some times we dont know the implementation
of the all method in parent class, at that time we can just declare the method
without any defination.

==================================================
11. Answer

An inherited class only can access protected data member.

==================================================
12. Answer


This can be achieved by A ref = new C();
==================================================
13. Answer


instanceOf keyword is to check whether a given object is belongs to a specific class or not.
==================================================
14. Answer

Interfaces contain only abstract methods.
Abstract classes can contains normal methods and abstract methods as well.

Using interfaces , A class can implement more than one interface.
Using abstract class, A class can extends only once class.

==================================================
15. Answer

AWT and Swing are advance java concepts.
Where AWT stands for Abstact Window Toolkit used for variables grapic related code.
==================================================
16. Answer

The classes a separated due to modularity of code.
and can resuable in any manner.
==================================================
20. Answer


  All recursive methods must be called by iteself in defination of method.
And it should contain a base condtion to exit the loop.
==================================================
21. Answer


  
  The base case is required inorder to exit the loop from recursive call.
This is an important aspect while writing a recursive method.
==================================================