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

Java Programing: Inheritance is an example of what type of relationship? a. is-a

ID: 3806007 • Letter: J

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 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

a.

is-a

c.

was-a

b.

has-a

d.

had-a

Explanation / Answer

1)Answer: a. is-a

Reason:   inheritance is the process of deriving class from an old one.the old class is known as super class/base class/parent class and the new one one is known as sub class/derived class/child class.

2) Answer: Derived class

Reason: Inheritance allows the class to inherit all the variables and methods of their parent class/ child class or sub class.

3)Answer: b.shape is a super class and circle and squares are subclasses of shape.

4)Answer: d. class parakeet extends bird{ }

5) Answer:a.single inheritance

Reason:   Java does not support multiple inheritance but this problem is solved through the interface

7)Answer: b. Because of single inheritrance,Retriever can extend no other class except dog.

8) Answer: Four

(ii) Answer: b.only (ii)

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