Question
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
-
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
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
-
Below is the incomplete code for a "Rat" class. Choose the correct code for its overloaded constructor.
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
-
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
-
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
-
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
-
True or False: multiple subclasses can extend from the the same superclass
True
False
QUESTION 7
-
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
-
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started