Filters
Question type

Study Flashcards

Interface classes cannot be extended but classes that implement interfaces can be extended.

A) True
B) False

Correct Answer

verifed

verified

Inheritance through an extended (derived) class supports which of the following concepts?


A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness

F) B) and C)
G) B) and E)

Correct Answer

verifed

verified

Example Code Ch 09-5 Consider the following class definition: public class AClass { protected int x; protected int y; public AClass(int a, int b) { x = a; y = b; } public int addEm() { return x + y; } public void changeEm() { x++; y--; } public String toString() { return "" + x + " " + y; } } -Refer to Example Code Ch 09-5: You want to extend AClass to BClass. BClass will have a third int instance data, z. Which of the following would best define BClass's constructor?


A) public BClass(int a, int b, int c)
{
Super(a, b, c) ;
}
B) public BClass(int a, int b, int c)
{
X = a;
Y = b;
Z = c;
}
C) public BClass(int a, int b, int c)
{
Z = c;
}
D) public BClass(int a, int b, int c)
{
Super(a, b) ;
Z = c;
}
E) public BClass(int a, int b, int c)
{
Super() ;
}

F) A) and D)
G) B) and D)

Correct Answer

verifed

verified

The relationship between a parent class and a child class is referred to as a(n) __________ relationship.


A) has-a
B) is-a
C) was-a
D) instance-of
E) alias

F) B) and D)
G) B) and C)

Correct Answer

verifed

verified

Example Code Ch 09-3 Consider the class Car and the subclass SportsCar. Car has instance data of currentSpeed, type, year, cost, model, color and methods of accelerate, brake, getGasMileage, getInsuranceRate and determineSpeed. -Refer to Example Code Ch 09-3: What methods inherited from Car should SportsCar override?

Correct Answer

verifed

verified

Because a SportsCar will have different ...

View Answer

Example Code Ch 09-2 Assume that Poodle is a derived class of Dog and that Dog d = new Dog(...) and Poodle p = new Poodle(...) where the ... are the necessary parameters for the two classes. -Refer to Example Code Ch 09-2: The assignment statement p = d; is legal even though p is not a Dog.

A) True
B) False

Correct Answer

verifed

verified

Which of the following is correct?


A) a base class is a parent class or super class
B) a base class is a child class or derived class
C) a child class is a super class of its parent
D) a parent class is a subclass of its child
E) None of these are correct

F) B) and D)
G) A) and C)

Correct Answer

verifed

verified

Example Code Ch 09-4 Given the following partial class definition: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } -Refer to Example Code Ch 09-4: Which of the following lists of instance data are accessible in class A3?


A) x, y, z, a, b, q
B) a, b, q
C) a, q
D) x, z, a, q
E) x, a, q

F) C) and D)
G) A) and B)

Correct Answer

verifed

verified

Example Code Ch 09-5 Consider the following class definition: public class AClass { protected int x; protected int y; public AClass(int a, int b) { x = a; y = b; } public int addEm() { return x + y; } public void changeEm() { x++; y--; } public String toString() { return "" + x + " " + y; } } -Refer to Example Code Ch 09-5: You want addEm to now add all three values, return the sum, and changeEm to change x and y, but leave z alone. Which should you do?


A) Redefine addEm and changeEm without referencing super.addEm() or super.changeEm() .
B) Redefine addEm to return the value of z+super.addEm() , but leave changeEm alone.
C) Redefine changeEm to call super.changeEm() and then set z = x + y, but leave addEm alone.
D) Redefine addEm to return the value of z+super.addEm() and redefine changeEm to call super.changeEm() and then set z = x + y.
E) Redefine changeEm to call super.changeEm() without doing anything to z, and redefine addEm to return super.addEm() .

F) A) and D)
G) A) and C)

Correct Answer

verifed

verified

Showing 41 - 49 of 49

Related Exams

Show Answer