Java OOP

 

SHORT ANSWER QUESTIONS

INHERITANCE & POLYMORPHISM I

 

QUESTIONS

 

1-_______________ is the concept of making a subclass class get all of the properties and functionality of another class.  More properties and functionality can be added in the subclass as needed.

2-An object of the subclass’ type has a(n) _______________ relationship with an object of the superclass’ type.

 

3-A(n) _________________ ___________________ diagram is a visual representation of how the different classes are related to each other.


4-The class that inherits from another class is called a ____________ or a ____________ class.

 

5-The class that is inherited from is known as the ____________ or the ____________ class.

6-The ______________ keyword is placed at the end of a class header to specify that the class will inherit from another class.

7-If Tool and Hammer are both classes, which one would be the superclass?

8-If Foot and BodyPart are both classes, which one would be the subclass?

9-Create a class diagram for the following types of items:

BathroomTool

ToothBrush

BathroomProduct

Plunger

FaceCloth

Toothpaste

HairBrush

HairGel

HandSoap

BathroomConsumable

ToiletPaper

Shampoo


10-Are these classes suitable for use with inheritance?

 

a)    Circle, Rectangle, Square, Shape

b)    Cup, Marker, Shoe, House

c)     Apple, Banana, Orange, Fruit, Food

d)    Carrot, Celery, Radish, Green Pepper

e)    Missile, HomingMissile, FastMissile, LongRangeMissile, Cannon

 

11-The subclass inherits the ____________ ______________ and the _____________ _____________ from the superclass.  It doesn’t inherit the constructors.

12-A method in the subclass with the same method header as a method in the superclass is a(n) _____________ ______________.

13-The first statement in every constructor in a subclass should be a call to the ________________, which is the constructor in the _________________.

 

14-We call the superconstructor by using the _____________ keyword.  We also have to include parameters that match the parameters in one of the superconstructors.

 

15-What is missing to make the Table class inherit from the Furniture class?  Add it.

Superclass

Subclass

public class Furniture
{
   //implementation not shown
}

public class Table
{

   //implementation not shown

}

 

16-What is missing in the subclass constructor?

Superclass

Subclass

public class Character
{
   //only the constructor is shown

 

   public Character(String n)
   {

name = n;

   }

 

   public Character()
   {

name = "Steve";

   }


}

public class Knight extends Character
{

   //only the constructor is shown

 

   public Knight (int lev)

   {

      super(2);

      level = lev;

   }

}

 

 

SOLUTIONS

 

Click here.