ITSC 1213 QUESTIONS AND ANSWERS SET A+
✔✔A car dealership needs a program to store information about the cars for sale. For
each car, they want to keep track of the following information: number of doors (2 or 4),
whether the car has air conditioning, and its average number of miles per gallon. Which
of the following is the best design? - ✔✔Use a class Car, with fields: numDoors, hasAir,
and milesPerGallon.
✔✔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()?
Animal[] a = { new Cat(), new Cow(), new Dog(), new Pig(), new Bird() } - ✔✔Meow Moo
Woof Awk Awk
✔✔What Java keyword is used to set up an inheritance relationship between a subclass
and a superclass? - ✔✔extends
✔✔What best describes the purpose of a class's constructor? - ✔✔Initialize the fields in
the object.
✔✔define polymorphism: - ✔✔NOT using the same name for a method but altering
which parameters it accepts for increased specificity
✔✔Given the following class definitions and a declaration of Book b = new Dictionary
which of the following will cause a compile-time error?
public class Book
{
public String getISBN()
{
// implementation not shown
, }
// constructors, fields, and other methods not shown
}
public class Dictionary extends Book
{
public String getDefinition()
{
//
implementation not shown
}
} - ✔✔b.getDefintion();
✔✔Given the following class declarations, what is the output from Student s1 = new
GradStudent(); followed by s1.getInfo();?
public class Student
{
public String getFood()
{
return "Pizza";
}
public String getInfo()
{
return this.getFood();
}
}
public class GradStudent extends Student
{
public String getFood()
{
return "Taco";
}
} - ✔✔Taco
✔✔Below is the class Greeter and its method, greet:
public class Greeter{ public String greet() { return "Hi"; }
}
What is the correct way to implement the overridden get method of the child class,
MeanGreeter, so that it returns "Go Away"?
I.
class MeanGreeter extends Greeter{ public String greet() { return "Go Away"; }}
II.
✔✔A car dealership needs a program to store information about the cars for sale. For
each car, they want to keep track of the following information: number of doors (2 or 4),
whether the car has air conditioning, and its average number of miles per gallon. Which
of the following is the best design? - ✔✔Use a class Car, with fields: numDoors, hasAir,
and milesPerGallon.
✔✔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()?
Animal[] a = { new Cat(), new Cow(), new Dog(), new Pig(), new Bird() } - ✔✔Meow Moo
Woof Awk Awk
✔✔What Java keyword is used to set up an inheritance relationship between a subclass
and a superclass? - ✔✔extends
✔✔What best describes the purpose of a class's constructor? - ✔✔Initialize the fields in
the object.
✔✔define polymorphism: - ✔✔NOT using the same name for a method but altering
which parameters it accepts for increased specificity
✔✔Given the following class definitions and a declaration of Book b = new Dictionary
which of the following will cause a compile-time error?
public class Book
{
public String getISBN()
{
// implementation not shown
, }
// constructors, fields, and other methods not shown
}
public class Dictionary extends Book
{
public String getDefinition()
{
//
implementation not shown
}
} - ✔✔b.getDefintion();
✔✔Given the following class declarations, what is the output from Student s1 = new
GradStudent(); followed by s1.getInfo();?
public class Student
{
public String getFood()
{
return "Pizza";
}
public String getInfo()
{
return this.getFood();
}
}
public class GradStudent extends Student
{
public String getFood()
{
return "Taco";
}
} - ✔✔Taco
✔✔Below is the class Greeter and its method, greet:
public class Greeter{ public String greet() { return "Hi"; }
}
What is the correct way to implement the overridden get method of the child class,
MeanGreeter, so that it returns "Go Away"?
I.
class MeanGreeter extends Greeter{ public String greet() { return "Go Away"; }}
II.