ITSC 1213 - Test 3 Answers

Ace your homework & exams now with Quizwiz!

Restaurant is a completely defined abstract class. Restaurant has a default constructor and an abstract method, setTable(). You include the following code segment in your program: Restaurant restaurant = new Restaurant(); What is the result?

A compile error

If a java class named Dog inherits a class named Animal then

Animal is the superclass and Dog is the subclass

Which of the following apply to both abstract Java classes and concrete Java classes?

Both may contain concrete methods

If Dog inherits Animal, what is the first thing that must happen within the Dog constructor when a Dog object is created? Assume Animal does not have a default constructor.

Call the Animal constructor

Dog inherits Animal. Animal has a private field named dietField and a public getter/setter method pair to access dietField. How may Dog access dietField?

Dog inherits the public getter/setter methods. It may access dietField through these methods.

Which of the data types below would be considered aggregation if you used them to define fields in a given class.

Double String Integer Turtle

Dog inherits Animal. Dog has a public method getBreed(). Animal does not have a getBreed() method. What access does Animal have to the getBreed() method that is in Dog?

Even though getBreed() is public, Animal has NO access because Dog inherits Animal, but Animal does not inherit Dog. or Only Dog objects created within the Animal class can call the getBreed() method

Dog inherits Animal. Some methods of Dog may have the same name as methods of Animal. If you create a Dog object and and call one of these methods, which version of the method gets control (i.e. is executed)?

If the methods have identical signatures, control is passed to the Dog version of the method. or If the methods have identical signatures, control is passed to the Animal method.

Animal is a fully defined class with a default constructor. You have two other classes: Dog and Collie. Dog extends Animal. Collie extends Dog. Dog dog = new Dog(); Collie collie = new Collie(); Animal animal = new Animal(); animal = dog; animal = collie; What results from the above code?

It compiles and executes with no errors

You have a fully defined class named Author. Author has a default constructor. You are defining a new class, Book. One of the fields of Book is an Author object reference variable. When must you call the Author constructor?

It is called automatically when you instantiate the Author object within Book.

Animal is a fully defined class. A class named Whale inherits Animal. Whale has a public int field named weightField. Animal does not have any public fields. Each of these classes has a default constructor. The constructor of Animal sets the Animal weightField = 100. The constructor of Whale sets the Whale weightField = 1000. You write a program which includes the following code segment: Animal animal; Whale whale = new Whale(); animal = whale; System.out.println(animal.weightField); What happens when the last line is processed?

Nothing. The last line produces a compile error.

Animal is a fully defined class. You define a second class, Lion which inherits Animal, and you define a method in Lion called getHeight(). Animal does not have a method called getHeight(). What is the result when the following lines are executed? Lion lion = new Lion(); Animal animal; animal = lion; animal.getHeight();

The code will cause a compile error

A class named Actor extends class Movie and both classes have a method called getName() that contains different code. An actor object tomCruise and a movie object missionImpossible have been created. Assume tomCruise gets assigned to missionImpossible (i.e. missionImpossible = tomCruise) and we call missionImpossible.getName(), the code inside of the getName() method in the Actor class will be executed. To get a polymorphic operation as described above, which of the following must be true.

The getName() method must be a member of the subclass: Actor The getName() method must be a member in the superclass: Movie The superclass and subclass method return types must be the same. The superclass and subclass method signatures must be the same

Which of the following are valid data types for fields of a class?

Turtle String int double

You define a class, Animal, and create an object of Animal, pantherObject. You do not include a toString() method in Animal. Would the following code compile and execute normally: pantherObject.toString();

Yes. Because Animal inherits the Java class, Object. Object includes a toString() method which is automatically inherited by your class, Animal.

Which of the following are not true about Java interfaces.

You can create objects of (instantiate) the interface class

Animal is a fully defined class with a default constructor. You have three other classes: Dog, Cat, and Bird. Classes Dog and Cat extend Animal. Dog dog = new Dog(); Cat cat = new Cat(); Bird bird = new Bird(); Animal animal = new Animal(); animal = dog; animal = cat; animal = bird; What results from the above code?

animal = bird; causes a compile error

What is the output when the following program executes? public class GenericPrint<T> { T field1; public GenericPrint(T field1) { super(); this.field1 = field1; } public void printField1() { System.out.println("field1 = " + field1); } } public class Main { public static void main (String[] args) { GenericPrint genericPrint1 = new GenericPrint(new Integer(110)); genericPrint1.printField1(); } }

field1 = 110

What is the output when the following program executes? public class GenericPrint<T> { T field1; public GenericPrint(T field1) { super(); this.field1 = field1; } public void printField1() { System.out.println("field1 = " + field1); } } public class Main { public static void main (String[] args) { GenericPrint genericPrint1 = new GenericPrint(new Float(110f)); genericPrint1.printField1(); } }

field1 = 110.0

Animal is a fully defined class with a method called getHeight(). You define a second class, Lion which inherits Animal, and you define a method in Lion also called getHeight(). Which getHeight() method would be called in the following code segment: Lion lion = new Lion(); Animal animal; animal = lion; animal.getHeight();

getHeight() method of Lion

Polymorphism applies to which of the following

methods

Which of the following could be the header of the abstract class Restaurant?

private abstract Restaurant abstract public Restaurant abstract Restaurant public abstract Restaurant

If Dog inherits Animal, Dog has direct access to the ___________________ members of Animal.

public

Which of the following is NOT a correct way to define the abstract method setTable()?

public abstract void setTable() { ... }

Thing1 and Thing2 are two completely defined Java interfaces. CatInTheHat is a completely defined abstract class. You are defining a new concrete class, DrSuess; and DrSuess should inherit CatInTheHat and implement both Thing1 and Thing2. Which of the following would be an acceptable header for DrSuess.

public class DrSuess extends CatInTheHat implements Thing1, Thing2

Thing1 and Thing2 are two completely defined Java interfaces. You are defining a new concrete class, DrSuess; and DrSuess should implement both Thing1 and Thing2. Which of the following would be an acceptable header for DrSuess?

public class DrSuess implements Thing1, Thing2

If you want a class called Collie to inherit both Dog and Animal, how should the headers of three classes appear?

public void Animal() public void Dog() extends Animal public void Collie() extends Dog

What is the proper class header for Dog if Dog inherits Animal?

public void Dog() extends Animal

Dog inherits Animal. Animal has only one constructor, and it requires a single String parameter. In the Dog constructor, how is the Animal constructor called?

super(<String_parameter>);

Match the code in the UML diagram with its meaning: Employee -name:String -payRate:double -EMPLOYEE_ID:int -nextID:int +STARTING_PAY_RATE:double +Employee(String) +Employee(String, double) +getName():String +getEmployeeID():int +getPayRate():double +changeName(String):void +changePayRate(double):void +getNextID():int

-name:String private field -EMPLOYEE_ID:int private final field -nextID:int private static field +STARTING_PAY_RATE:double public static final +Employee(String) public constructor +getNextID():int public static method

Animal is a fully defined class. A class named Whale inherits Animal. Each of classes has a public int field named weightField. Each of these classes has a default constructor. The constructor of Animal sets the Animal weightField = 100. The constructor of Whale sets the Whale weightField = 1000. You write a program which includes the following code segment: Animal animal; Whale whale = new Whale(); animal = whale; System.out.println(animal.weightField); What happens when the last line is processed?

100 is printed


Related study sets

Other Compute Services: ECS, Lambda, Batch, Lightsail

View Set

Infant & Child Development Chapter 7

View Set

Chapter 16 - Life of the Cenozoic

View Set

2.5 Overview of Organic Compounds

View Set

Blood- Mastering formed elements

View Set

CIPP US Module 10 - Telecom and Marketing

View Set