Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 If A Is-A B, what else can we say about the relationship between class A and class B? 1 Class A extends class

Question 1

If A "Is-A" B, what else can we say about the relationship between class A and class B?

1 Class A extends class B

2 Class A inherits from class B

3 Class A derives from class B.

4 None of the above.

5 All of the above.

Question 2

What tool is used to show inheritance or composition relationships among classes.

1 a class diagram

2 a flow chart

3 an object diagram

4 a family tree

Question 3

Which of the following is a specialized version of a class.

1 an ancestor

2 a subclass

3 a superclass

4 class Object

5 class Class

Question 4

Which of the following statements is true?

1 Objects NEVER change the class to which they belong.

2 In some situations, a variable may be bound to DIFFERENT types of objects.

3 The behavior of any object is determined by the OBJECT'S CLASS and not by the data type of the variable that references it.

4 All of the above.

5 None of the above.

Question 5

Given this start to a class definition: public class Beta extends Alpha { ... } What is true about instance variables from Alpha?

1 Class Beta must redeclare all of Alpha's instance variables.

2 They should not be redeclared in Beta.

3 The Beta class should redeclare only those instance variables from Alpha that it wants.

4 Class Beta should redeclare only the private instance variables from Alpha.

5 None of the above

Question 6

If class Fruit is the superclass of class Apple, which of the following is also true?

1 Fruit is the base class of Apple

2 Fruit is the parent class of Apple

3 Apple "Is-A" Fruit

4 All of the above

5 None of the above

Flag this Question

Question 7

If a class definition does not include the keyword extends, which of the following is true?

1 The class has no sub class

2 The class has no super class

3 The class implicitly derives from Class.

4 The class implicitly derives from Object.

5 None of the above

Question 8

Which of the following things would prevent a method declaration in a subclass from properly overriding an inherited method?

1 not matching the method name

2 not matching the return type

3 not matching the parameter "signature" (number, order and data types of parameters)

4 trying to make a public method private

5 All of the above

Question 9

What is always the very first thing that occurs in the constructor of a derived class?

1 instance variables are initialized

2 the value true is returned

3 a call to the superclass constructor is made

4 Flag this Question

Question 10

Which of the following statements creates a composition (or aggregation) relationship?

1 public class Fun extends Hun { ... }

2 return new Fun();

3 if ( myThing instanceof Point ) { ... }

4 private Widget myThing;

5 Boo Hoo

Question 11

Which Java keyword can be used to access the super class version of an overridden method from within the sub class?

1 override

2 super

3 new

4 this

5 extends

Question 12

Given the following code (assume that the statements compile with NO syntax errors):

Red hot = new Red(); Green top = hot; Orange ocean = new Blue(); hot = ocean;

What is the static type of 'top'?

1 Green

2 hot

3 Red

4 top

Question 13

Given the following code (assume that the statements compile with NO syntax errors):

Red hot = new Red(); Green top = hot; Orange ocean = new Blue(); hot = ocean;

What is the dynamic type of 'ocean' after all the statements have been executed? (Tip: draw an object diagram!)

1 Orange

2 hot

3 Red

4 Blue

Question 14

Given the following code (assume that the statements compile with NO syntax errors):

Red hot = new Red(); Green top = hot; Orange ocean = new Blue(); hot = ocean;

What is the dynamic type of 'hot' after all the statements have been executed? (Tip: draw an object diagram!)

1 Red

2 ocean

3 Blue

4 Orange

Question 15

What determines which version of an overridden method is executed?

1 the static type of the variable that acts as the 'qualifier' in the method call

2 the dynamic type of the variable that acts as the 'qualifier' in the method call

3 the data types of the arguments of the method call

4 the name of the class where the method call is located

5 the name of the method

Question 16

What determines which version of an overloaded method is executed?

1 the static type of the variable that acts as the 'qualifier' in the method call

2 the dynamic type of the variable that acts as the 'qualifier' in the method call

3 the data types of the arguments of the method call

4 the name of the class where the method call is located

5 the name of the method

Question 17

A programmer writing code in class Point attempts to override the following inherited method: public boolean equals( Object o ) { ... } but does not match the method signature exactly. Instead, the programmer uses the following method signature: public boolean equals( Point p ) { ... } What is the result?

1 A syntax error occurs because the method signatures do not match.

2 The code compiles and works fine -- the method has been successfully overridden.

3 The code compiles, but the inherited method has not been overridden -- it has been overloaded instead.

4 The compiler automatically changes the method signature to match the inherited method.

5 The compiler issues a warning, but the method is successfully overridden.

Question 18

Given the following class hierarchy: Siamese "Is-A" Feline "Is-A" Mammal "Is-A" LivingThing Which of the following is true?

1 ( new Mammal() ) instanceof LivingThing

2 ( new Feline() ) instanceof LivingThing

3 ( new Siamese() ) instanceof LivingThing

4 All of the above

5 None of the above

Question 19

A type cast using reference type is a promise to the compiler that the dynamic type of the expression will conform to the type specified in the cast. What happens if this promise is broken?

1 A syntax error will occur.

2 The dynamic type will be changed to match the type specified in the cast.

3 A ClassCastException will be thrown.

4 The JRE will request a replacement type from the user.

5 The type cast will be ignored.

Question 20

How many different classes can a sub class derive from, using the keyword extends?

1 A sub class can extend directly from mutliple super classes.

2 exactly one class

3 any number of classes as long as an import statement is used

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

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

4. Help trainees set challenging mastery or learning goals.

Answered: 1 week ago

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago