Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 If A \"Is-A\" B, what else can we say about the relationship between

ID: 3919399 • Letter: Q

Question


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

Class A extends class B

Class A inherits from class B

Class A derives from class B.

None of the above.

All of the above.


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

a class diagram

a flow chart

an object diagram

a family tree


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

an ancestor

a subclass

a superclass

class Object

class Class


Question 4
Which of the following statements is true?

Objects NEVER change the class to which they belong.

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

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

All of the above.

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?

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

They should not be redeclared in Beta.

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

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

None of the above


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

Fruit is the base class of Apple

Fruit is the parent class of Apple

Apple "Is-A" Fruit

All of the above

None of the above


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

The class has no sub class

The class has no super class

The class implicitly derives from Class.

The class implicitly derives from Object.

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?

not matching the method name

not matching the return type

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

trying to make a public method private

All of the above


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

instance variables are initialized

the value true is returned

a call to the superclass constructor is made


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

public class Fun extends Hun { ... }

return new Fun();

if ( myThing instanceof Point ) { ... }

private Widget myThing;

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?

override

super

new

this

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'?

Green

hot

Red

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!)

Orange

hot

Red

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!)

Red

ocean

Blue

Orange


Question 15
What determines which version of an overridden method is executed?

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

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

the data types of the arguments of the method call

the name of the class where the method call is located

the name of the method


Question 16
What determines which version of an overloaded method is executed?

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

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

the data types of the arguments of the method call

the name of the class where the method call is located

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?

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

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

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

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

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?

( new Mammal() ) instanceof LivingThing

( new Feline() ) instanceof LivingThing

( new Siamese() ) instanceof LivingThing

All of the above

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?

A syntax error will occur.

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

A ClassCastException will be thrown.

The JRE will request a replacement type from the user.

The type cast will be ignored.


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

A sub class can extend directly from mutliple super classes.

exactly one class

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

Explanation / Answer

Note: According to the chegg policy we are bound to solve first 4 questions when there are many questions posted but here I am giving you the 5 answers, you can repost the remaining the questions.

ANSWER 1: Here option(A) is correct because we know that  IS-A relationship denotes “one object is type of another”. IS-A relation denotes Inheritance methodology. In Java, Inheritance can be implemented with extends (in case of class) and implements(in case of interface) keywords.

ANSWER 2: Here also option(A) is correct because Class diagrams are one of the most useful types of diagrams in UML as they clearly map out the structure of a particular system by modeling its classes, attributes, operations, and relationships between objects.

ANSWER 3: Here option(C) is correct beacuse Object class is present in java.lang package. Every class in Java is directly or indirectly derived from the Object class. If a Class does not extend any other class then it is direct child class of Object and if extends other class then it is an indirectly derived. Therefore the Object class methods are available to all Java classes. Hence Object class acts as a root of inheritance hierarchy in any Java Program.

ANSWER 4: Here all of the above option is right.

ANSWER 5: Here option Class Beta should redeclare only the private instance variables from Alpha. is correct because A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass. I agree, that the field is there. But, subclass does not get any privilege on that private field.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote