Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 1 Below is the incomplete code for a Rat class that extends the Pet class used in the previous Lab. From the choices below,

QUESTION 1

  1. Below is the incomplete code for a "Rat" class that extends the Pet class used in the previous Lab. From the choices below, choose the most appropriate option for a method that could be added to this class

    image text in transcribed

    a

    void run() {

    System.out.println(name+": is running...");

    }

    b

    void bark() {

    System.out.println("Woof woof!");

    }

    c

    void eyes() {

    System.out.println("Eyes are: "+eyecolour);

    }

QUESTION 2

  1. Below is the incomplete code for a "Rat" class. Choose the correct code for its overloaded constructor. image text in transcribed

    a

    Rat(String name, String colour, int weight, String eyecolour, boolean hasRabies){

    super(name, colour, weight); this.eyecolour = eyecolour; this.hasRabies = hasRabies;

    }

    b

    Rat(String name, String colour, int weight){

    super(name, colour, weight);

    }

    c

    Rat(){

    super(); eyecolour = "Pink"; hasRabies = true;

    }

    d

    Rat(String eyecolour, boolean hasRabies){

    this.eyecolour = eyecolour; this.hasRabies = hasRabies;

    }

QUESTION 3

  1. For the Pet and Cat classes from the previous Lab, which statement below is correct?

    a

    To create an instance of the Cat class, you can only use the overloaded constructor

    b

    For a Cat object to have a 'name', you need to add a new data field called 'name' to the Cat class definition

    c

    An instance of the Cat class can be created even if the Pet class is deleted (not defined)

    d

    Creating an instance of Cat class using the default constructor will also invoke the default constructor of the Pet class

QUESTION 4

  1. For the Pet and Cat classes from the previous Lab, which statement below is correct?

    a

    The Pet class extends the Cat class

    b

    An instance of the Pet class cannot be declared on its own, only a 'Cat' object can be created

    c

    The sleep() method is not inherited by the Cat class

    d

    The Pet class is a superclass and the Cat class is a subclass

QUESTION 5

  1. Inheritance is important in Object Oriented Programming because:

    a

    It is not possible to create Object Oriented Programs without using inheritance

    b

    It reduces the amount of planning and design required in a program

    c

    It minimizes duplication of code when creating multiple related classes

QUESTION 6

  1. True or False: multiple subclasses can extend from the the same superclass

    True

    False

QUESTION 7

  1. Using the Pet and Cat classes from the previous Lab as a reference, which line of code properly creates a new instance of the Cat class?

    a

    Pet myCat = new Pet("Bob", "Orange", 8, true, "medium");

    b

    Cat myCat = new Cat("Bob", "Orange", 8, "medium", true);

    c

    Cat myCat = new Cat("Bob");

    d

    Cat myCat = new Cat("Bob", "Orange", 8, true, "medium");

QUESTION 8

  1. Which statement is false?

    a

    "class A extends B" means B is a subclass of A.

    b

    "class A extends B" means A is a subclass of B.

    c

    When an instance of a subclass is created, the superclass constructor (default or overloaded) is also invoked

    d

    A subclass usually has more datafields and methods than its superclass

class Rat extends Pet{ private String eyecolour; private boolean hasRabies; //Rest of class definition is missing class Rat extends Pet{ private String eyecolour; private boolean hasRabies; //Rest of class definition is missing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions