ITSC 1213 EXAM 2 QUESTIONS AND CORRECT
ANSWERS
Shirt inherits Clothing. Clothing has the fold()method, but Shirt does not. Which fold() is
executed in the following code?
Shirt myShirt = new Shirt();
myShirt.fold(); - Answers - The clothing version --> As the Shirt inherits Clothing so the
object of the Shirt class can call the method of Clothing
A bookstore is working on an on-line ordering system. For each type of published
material (books, movies, audio tapes) they need to track the id, title, author(s), date
published, and price.
Which of the following would be the best design? - Answers - Create the class
PublishedMaterial with children classes of Book, Movie, and AudioTape.
Below is the parent class Person:
public class Person { private String name = null;
public Person(String theName)
{
name = theName;
}
public String getFood()
{
return "Hamburger";
}
}
Which of the following method signatures in Student would correctly override the
getFood method in Person? - Answers - public String getFood()
Given the following class declarations and initializations in a client program, which of the
following is a correct call to method1?
public class Test1 {
public void method1(Test2 v1, Test3 v2) {
// rest of method not shown } }
public class Test2 extends Test1 { }
public class Test3 extends Test2 { }
The following initializations appear in a different class.
, Test1 t1 = new Test1();
Test2 t2 = new Test2();
Test3 t3 = new Test3(); - Answers - t3.method1(t3,t3);
The class Shirt extends the Clothing class. To make the class DressShirt inherit the
functionality of both Clothing and Shirt its class header would be: - Answers - public
class DressShirt extends Shirt
Which of the following is true regarding abstract classes or abstract methods? (Select
all that apply) - Answers - Abstract classes only become useful when they are extended.
Abstract methods must be overriden
An online store is working on an online ordering system for Books and Movies. For each
type of Published Material (books and movies) they need to track the id, title, date
published, and price. Which of the following would be the best design? - Answers -
Create the class PublishedMaterial and have Book and Movie inherit from it all the listed
attributes.
Below is the class Greeter and its method, greet:
public class Greeter{
public String greet() {
return "Hi"; }}
Which of the following are the correct way to create a subclass called MeanGreeter and
implement the overridden greet method of the child class so that it returns "Go Away"?
(Select all that apply) - Answers - class MeanGreeter extends Greeter
{
public String greet()
{
return "Go Away";
}
}
Under which of these conditions overloading a method would work (ie: the class will
contain two methods with the same name)? - Answers - The methods have different
numbers of parameters.
If you have a parent class Animal that has a method speak() which returns: Awk. Cat
has a speak method that returns: Meow. Bird does not have a speak method. Dog has a
speak method that returns: Woof. Pig does not have a speak method. Cow has a speak
method that returns: Moo. What is the output from looping through the array a created
below and asking each element to speak()?
ANSWERS
Shirt inherits Clothing. Clothing has the fold()method, but Shirt does not. Which fold() is
executed in the following code?
Shirt myShirt = new Shirt();
myShirt.fold(); - Answers - The clothing version --> As the Shirt inherits Clothing so the
object of the Shirt class can call the method of Clothing
A bookstore is working on an on-line ordering system. For each type of published
material (books, movies, audio tapes) they need to track the id, title, author(s), date
published, and price.
Which of the following would be the best design? - Answers - Create the class
PublishedMaterial with children classes of Book, Movie, and AudioTape.
Below is the parent class Person:
public class Person { private String name = null;
public Person(String theName)
{
name = theName;
}
public String getFood()
{
return "Hamburger";
}
}
Which of the following method signatures in Student would correctly override the
getFood method in Person? - Answers - public String getFood()
Given the following class declarations and initializations in a client program, which of the
following is a correct call to method1?
public class Test1 {
public void method1(Test2 v1, Test3 v2) {
// rest of method not shown } }
public class Test2 extends Test1 { }
public class Test3 extends Test2 { }
The following initializations appear in a different class.
, Test1 t1 = new Test1();
Test2 t2 = new Test2();
Test3 t3 = new Test3(); - Answers - t3.method1(t3,t3);
The class Shirt extends the Clothing class. To make the class DressShirt inherit the
functionality of both Clothing and Shirt its class header would be: - Answers - public
class DressShirt extends Shirt
Which of the following is true regarding abstract classes or abstract methods? (Select
all that apply) - Answers - Abstract classes only become useful when they are extended.
Abstract methods must be overriden
An online store is working on an online ordering system for Books and Movies. For each
type of Published Material (books and movies) they need to track the id, title, date
published, and price. Which of the following would be the best design? - Answers -
Create the class PublishedMaterial and have Book and Movie inherit from it all the listed
attributes.
Below is the class Greeter and its method, greet:
public class Greeter{
public String greet() {
return "Hi"; }}
Which of the following are the correct way to create a subclass called MeanGreeter and
implement the overridden greet method of the child class so that it returns "Go Away"?
(Select all that apply) - Answers - class MeanGreeter extends Greeter
{
public String greet()
{
return "Go Away";
}
}
Under which of these conditions overloading a method would work (ie: the class will
contain two methods with the same name)? - Answers - The methods have different
numbers of parameters.
If you have a parent class Animal that has a method speak() which returns: Awk. Cat
has a speak method that returns: Meow. Bird does not have a speak method. Dog has a
speak method that returns: Woof. Pig does not have a speak method. Cow has a speak
method that returns: Moo. What is the output from looping through the array a created
below and asking each element to speak()?