Question: Java Programing: Inheritance is an example of what type of relationship? a. is-a c. was-a b. has-a d. had-a 2. Any new class you create
Java Programing:
Inheritance is an example of what type of relationship?
| a. | is-a | c. | was-a |
| b. | has-a | d. | had-a |
2. Any new class you create from an existing class is called a(n) ____.
| a. | base class | c. | derived class |
| b. | superclass | d. | extended class |
3. Suppose there are three classes named Shape, Circle, and Square. What is the most likely relationship between them?
| a. | Square is a superclass, and Shape and Circle are subclasses of Square. |
| b. | Shape is a superclass, and Circle and Square are subclasses of Shape. |
| c. | Shape, Circle, and Square are all sibling classes. |
| d. | These three classes cannot be related. |
4. What is the correct syntax for defining a new class Parakeet based on the superclass Bird?
| a. | class Parakeet isa Bird{ } |
| b. | class Bird defines Parakeet{ } |
| c. | class Bird hasa Parakeet{ } |
| d. | class Parakeet extends Bird{ } |
What type of inheritance does Java support?
| a. | single inheritance | c. | multiple inheritance |
| b. | double inheritance | d. | Java does not support inheritance. |
7. If class Dog has a subclass Retriever, which of the following is true?
| a. | Because of single inheritance, Dog can have no other subclasses. |
| b. | Because of single inheritance, Retriever can extend no other class except Dog. |
| c. | The relationship between these classes implies that Dog is-a Retriever. |
| d. | The relationship between these classes implies that Retriever has-a Dog. |
8. Consider the following class definitions.
public class BClass {
private int x;
private double y;
public void print() { }
}
public class DClass extends BClass
{
private int a;
private int b;
public void print() { }
}
Suppose that you have the following statement.
DClass dObject = new DClass();
How many instance variables does dObject have?
| a. | zero | c. | three |
| b. | two | d. | four |
Consider the following class definitions.
public class BClass
{
private int x;
public void set(int a)
{
x = a;
}
public void print()
{
System.out.print(x);
}
}
public class DClass extends BClass
{
private int y;
public void set(int a, int b)
{
//Postcondition: x = a; y = b;
}
public void print(){ }
}
Which of the following correctly redefines the method print of DClass?
(i)
public void print()
{
System.out.print(x + " " + y);
}
(ii)
public void print()
{
super.print();
System.out.print(" " + y);
}
a. Only (i) b. Only (ii)
c. Both (i) and (ii) d. None of these
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
