Deck 9: Inheritance

ملء الشاشة (f)
exit full mode
سؤال
The JavaFX API offers the programmer controls that allow the user to pick colors or specific dates.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Interface classes cannot be extended but classes that implement interfaces can be extended.
سؤال
Example Code Ch 09-1
Consider the following class hierarchy:
Example Code Ch 09-1 Consider the following class hierarchy:   Refer to Example Code Ch 09-1: If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B.<div style=padding-top: 35px>
Refer to Example Code Ch 09-1: If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B.
سؤال
The instruction super(); does which of the following?

A) It calls the method super as defined in the current class.
B) It calls the method super as defined in the current class's parent class.
C) It calls the method super as defined in java.lang.
D) It calls the constructor as defined in the current class.
E) It calls the constructor as defined in the current class's parent class.
سؤال
A derived class has access to all of the methods of the parent class, but only to the protected or public instance data of the parent class.
سؤال
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.
سؤال
Example Code Ch 09-1
Consider the following class hierarchy:
Example Code Ch 09-1 Consider the following class hierarchy:   Refer to Example Code Ch 09-1: A is a derived class of X.<div style=padding-top: 35px>
Refer to Example Code Ch 09-1: A is a derived class of X.
سؤال
You may use the super reserved word to access a parent class's private members.
سؤال
One way to allow for user interactivity in a program is to use a dialog box.
سؤال
Example Code Ch 09-1
Consider the following class hierarchy:
Example Code Ch 09-1 Consider the following class hierarchy:   Refer to Example Code Ch 09-1: Y is a derived class of Z.<div style=padding-top: 35px>
Refer to Example Code Ch 09-1: Y is a derived class of Z.
سؤال
The reserved word, extends, is used to denote a has-a relationship.
سؤال
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 is true with respect to A1, A2, and A3?

A) A1 is a subclass of A2 and A2 is a subclass of A3
B) A3 is a subclass of A2 and A2 is a subclass of A1
C) A1 and A2 are both subclasses of A3
D) A2 and A3 are both subclasses of A1
E) A1, A2 and A3 are all subclasses of the class A
سؤال
In order to use a dialog box to display an alert to the user, you must include the AlertType class.
سؤال
Java doesn't support multiple inheritance; but it does support the implementation of multiple interfaces.
سؤال
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 A2?

A) x, y, z, a, b
B) x, y, z, a
C) x, z, a, b
D) z, a, b
E) a, b
سؤال
The protected visibility modifier provides the best possible encapsulation that permits inheritance.
سؤال
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 d = p; is legal even though d is not a Poodle.
سؤال
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 is true regarding the use of instance data y of class A1?

A) It is accessible in A1, A2, and A3
B) It is accessible in A1 and A2
C) It is accessible only in A1
D) It is accessible only in A3
E) It is accessible to any of the three classes
سؤال
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
سؤال
If class AParentClass has a protected instance data x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but cannot redefine x to be a different type.
سؤال
Abstract methods are used when defining

A) interface classes
B) derived classes
C) classes that have no constructor
D) arrays
E) classes that have no methods
سؤال
Aside from permitting inheritance, the visibility modifier protected is also used to

A) permit access to the protected item by any class defined in the same package
B) permit access to the protected item by any static class
C) permit access to the protected item by any parent class
D) ensure that the class cannot throw a NullPointException
E) define abstract elements of an interface
سؤال
Using the reserved word super, one can

A) access a parent class's constructor(s)
B) access a parent class's methods and instance data
C) access a child class's constructor(s)
D) access a child class's methods and instance data
E) Both A and B are correct
سؤال
Java does not support multiple inheritance but some of the abilities of multiple inheritance are available by

A) importing classes
B) implementing interfaces
C) overriding parent class methods
D) creating aliases
E) using public rather than protected or private modifiers
سؤال
Inheritance through an extended (derived) class supports which of the following concepts?

A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness
سؤال
Which of the following is an example of multiple inheritance?

A) a computer can be a mainframe or a PC
B) a PC can be a desktop or a laptop
C) a laptop is both a PC and a portable device
D) a portable device is a lightweight device
E) Macintosh and IBM PC are both types of PCs
سؤال
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: Which of the following would best redefine the toString method for BClass?

A) public String toString(int z)
{
Return " " + x + " " + y + " " + z;
}
B) ) public String toString()
{
Return super.toString();
}
C) public String toString()
{
Return super.toString() + " " + z;
}
D) public String toString()
{
Return super.toString()+" " x+" "+y+" "+z;
}
E) public String toString()
{
Return " " + x + " + y + " " + z;
}
سؤال
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
سؤال
If a programmer writes a class that he wants to be extended by another programmer, then this programmer must

A) change private methods and instance data to be protected
B) change public methods and instance data to be protected
C) change all the methods to be protected
D) change the class to be protected
E) None of these; the programmer doesn't have to change anything
سؤال
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().
سؤال
All classes in Java are directly or indirectly subclasses of the __________ class.

A) Wrapper
B) String
C) Reference
D) this
E) Object
سؤال
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();
}
سؤال
If you instantiate an abstract class, the class or object you wind up with

A) is also an abstract class
B) is a normal class
C) is an interface
D) is a reference to an Object
E) you can't instantiate an abstract class
سؤال
Which of the following is true about Java classes?

A) All classes must have one parent but may have any number of children (derived or extended).
B) All classes must have one parent and may have a single child (derived or extended) but may have any number of parent classes.
C) All classes can have any number (zero or more) of parent classes and any number of children (derived or extended) classes.
D) All classes must have one parent and may have a single child (derived or extended) class.
E) All classes can have either zero or one parent class and any number of child (derived or extended) classes.
سؤال
Example Code Ch 09-6
Assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
Refer to Example Code Ch 09-6: The reference to getMoney() in assignment 2 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) This cannot be determined by examining the code
سؤال
Example Code Ch 09-6
Assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
Refer to Example Code Ch 09-6: The reference to getMoney() in assignment 3 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) This cannot be determined by examining the code
سؤال
Which of the following is not a method of the Object class?

A) clone
B) compareTo
C) equals
D) toString
E) All of the above are methods of the Object class
سؤال
Example Code Ch 09-6
Assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
Refer to Example Code Ch 09-6: The reference to getMoney() in assignment 1 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) This cannot be determined by examining the code
سؤال
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
سؤال
Two children of the same parent class are known as

A) aliases
B) relatives
C) clones
D) brothers
E) siblings
سؤال
Assume a class Triangle has been defined. It has three instance data, Point p1, p2, p3. The class also has a constructor that receives the 3 Points and initializes p1, p2, p3, a toString method that outputs the 3 Points, and a computeSurfaceArea method that calculates the surface area of the Triangle (as an int value). We want to extend this class to represent a 3-dimensional Pyramid, which consists of 4 Points. Since the Pyramid will consist of, in essence, 4 triangles, computeSurfaceArea for the Pyramid will compute 4 times the surface area of the Triangle made up of 3 of those 4 Points. Write the Pyramid class to handle the difference(s) between a Pyramid and the previously defined Triangle. Assume the instance data of Triangle are protected and all methods are public. Also assume that the class Point has a toString method.
سؤال
Why is it a contradiction for an abstract method to be modified as final or static?
سؤال
A motorcycle inherits properties from both a bicycle and a car. Java does not permit multiple inheritance. Assume that Bicycle and Car have both been declared. Explain how you might go about implementing a Motorcycle as a derived class.
سؤال
Consider a class Plane and three subclasses, Glider, PropPlane and Jet. What instance data that should be declared in Plane and what instance data should be declared in each of the three subclasses? Come up with at least 2 instance data unique to each of the four classes given that all instance data of Plane will be inherited into the subclasses.
سؤال
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.
Explain the difference between using an imported class and extending a class.
سؤال
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 instance data and methods might you define for SportsCar that are not part of Car?
سؤال
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?
سؤال
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.
Consider a class named Name which has four instance data (all Strings): first, last, middle, title. Even though Name inherits the equals method from Object, it would make sense to override it. Why?
سؤال
Explain the difference between implementing an interface and a derived class.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/49
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 9: Inheritance
1
The JavaFX API offers the programmer controls that allow the user to pick colors or specific dates.
True
2
Interface classes cannot be extended but classes that implement interfaces can be extended.
False
3
Example Code Ch 09-1
Consider the following class hierarchy:
Example Code Ch 09-1 Consider the following class hierarchy:   Refer to Example Code Ch 09-1: If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B.
Refer to Example Code Ch 09-1: If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B.
True
4
The instruction super(); does which of the following?

A) It calls the method super as defined in the current class.
B) It calls the method super as defined in the current class's parent class.
C) It calls the method super as defined in java.lang.
D) It calls the constructor as defined in the current class.
E) It calls the constructor as defined in the current class's parent class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
5
A derived class has access to all of the methods of the parent class, but only to the protected or public instance data of the parent class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
6
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
7
Example Code Ch 09-1
Consider the following class hierarchy:
Example Code Ch 09-1 Consider the following class hierarchy:   Refer to Example Code Ch 09-1: A is a derived class of X.
Refer to Example Code Ch 09-1: A is a derived class of X.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
8
You may use the super reserved word to access a parent class's private members.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
9
One way to allow for user interactivity in a program is to use a dialog box.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
10
Example Code Ch 09-1
Consider the following class hierarchy:
Example Code Ch 09-1 Consider the following class hierarchy:   Refer to Example Code Ch 09-1: Y is a derived class of Z.
Refer to Example Code Ch 09-1: Y is a derived class of Z.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
11
The reserved word, extends, is used to denote a has-a relationship.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
12
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 is true with respect to A1, A2, and A3?

A) A1 is a subclass of A2 and A2 is a subclass of A3
B) A3 is a subclass of A2 and A2 is a subclass of A1
C) A1 and A2 are both subclasses of A3
D) A2 and A3 are both subclasses of A1
E) A1, A2 and A3 are all subclasses of the class A
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
13
In order to use a dialog box to display an alert to the user, you must include the AlertType class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
14
Java doesn't support multiple inheritance; but it does support the implementation of multiple interfaces.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
15
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 A2?

A) x, y, z, a, b
B) x, y, z, a
C) x, z, a, b
D) z, a, b
E) a, b
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
16
The protected visibility modifier provides the best possible encapsulation that permits inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
17
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 d = p; is legal even though d is not a Poodle.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
18
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 is true regarding the use of instance data y of class A1?

A) It is accessible in A1, A2, and A3
B) It is accessible in A1 and A2
C) It is accessible only in A1
D) It is accessible only in A3
E) It is accessible to any of the three classes
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
19
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
20
If class AParentClass has a protected instance data x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but cannot redefine x to be a different type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
21
Abstract methods are used when defining

A) interface classes
B) derived classes
C) classes that have no constructor
D) arrays
E) classes that have no methods
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
22
Aside from permitting inheritance, the visibility modifier protected is also used to

A) permit access to the protected item by any class defined in the same package
B) permit access to the protected item by any static class
C) permit access to the protected item by any parent class
D) ensure that the class cannot throw a NullPointException
E) define abstract elements of an interface
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
23
Using the reserved word super, one can

A) access a parent class's constructor(s)
B) access a parent class's methods and instance data
C) access a child class's constructor(s)
D) access a child class's methods and instance data
E) Both A and B are correct
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
24
Java does not support multiple inheritance but some of the abilities of multiple inheritance are available by

A) importing classes
B) implementing interfaces
C) overriding parent class methods
D) creating aliases
E) using public rather than protected or private modifiers
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
25
Inheritance through an extended (derived) class supports which of the following concepts?

A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
26
Which of the following is an example of multiple inheritance?

A) a computer can be a mainframe or a PC
B) a PC can be a desktop or a laptop
C) a laptop is both a PC and a portable device
D) a portable device is a lightweight device
E) Macintosh and IBM PC are both types of PCs
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
27
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: Which of the following would best redefine the toString method for BClass?

A) public String toString(int z)
{
Return " " + x + " " + y + " " + z;
}
B) ) public String toString()
{
Return super.toString();
}
C) public String toString()
{
Return super.toString() + " " + z;
}
D) public String toString()
{
Return super.toString()+" " x+" "+y+" "+z;
}
E) public String toString()
{
Return " " + x + " + y + " " + z;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
28
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
29
If a programmer writes a class that he wants to be extended by another programmer, then this programmer must

A) change private methods and instance data to be protected
B) change public methods and instance data to be protected
C) change all the methods to be protected
D) change the class to be protected
E) None of these; the programmer doesn't have to change anything
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
30
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().
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
31
All classes in Java are directly or indirectly subclasses of the __________ class.

A) Wrapper
B) String
C) Reference
D) this
E) Object
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
32
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();
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
33
If you instantiate an abstract class, the class or object you wind up with

A) is also an abstract class
B) is a normal class
C) is an interface
D) is a reference to an Object
E) you can't instantiate an abstract class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which of the following is true about Java classes?

A) All classes must have one parent but may have any number of children (derived or extended).
B) All classes must have one parent and may have a single child (derived or extended) but may have any number of parent classes.
C) All classes can have any number (zero or more) of parent classes and any number of children (derived or extended) classes.
D) All classes must have one parent and may have a single child (derived or extended) class.
E) All classes can have either zero or one parent class and any number of child (derived or extended) classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
35
Example Code Ch 09-6
Assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
Refer to Example Code Ch 09-6: The reference to getMoney() in assignment 2 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) This cannot be determined by examining the code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
36
Example Code Ch 09-6
Assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
Refer to Example Code Ch 09-6: The reference to getMoney() in assignment 3 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) This cannot be determined by examining the code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
37
Which of the following is not a method of the Object class?

A) clone
B) compareTo
C) equals
D) toString
E) All of the above are methods of the Object class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
38
Example Code Ch 09-6
Assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
Refer to Example Code Ch 09-6: The reference to getMoney() in assignment 1 is to the class

A) Person
B) Student
C) Employee
D) Retired
E) This cannot be determined by examining the code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
39
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
40
Two children of the same parent class are known as

A) aliases
B) relatives
C) clones
D) brothers
E) siblings
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
41
Assume a class Triangle has been defined. It has three instance data, Point p1, p2, p3. The class also has a constructor that receives the 3 Points and initializes p1, p2, p3, a toString method that outputs the 3 Points, and a computeSurfaceArea method that calculates the surface area of the Triangle (as an int value). We want to extend this class to represent a 3-dimensional Pyramid, which consists of 4 Points. Since the Pyramid will consist of, in essence, 4 triangles, computeSurfaceArea for the Pyramid will compute 4 times the surface area of the Triangle made up of 3 of those 4 Points. Write the Pyramid class to handle the difference(s) between a Pyramid and the previously defined Triangle. Assume the instance data of Triangle are protected and all methods are public. Also assume that the class Point has a toString method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
42
Why is it a contradiction for an abstract method to be modified as final or static?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
43
A motorcycle inherits properties from both a bicycle and a car. Java does not permit multiple inheritance. Assume that Bicycle and Car have both been declared. Explain how you might go about implementing a Motorcycle as a derived class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
44
Consider a class Plane and three subclasses, Glider, PropPlane and Jet. What instance data that should be declared in Plane and what instance data should be declared in each of the three subclasses? Come up with at least 2 instance data unique to each of the four classes given that all instance data of Plane will be inherited into the subclasses.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
45
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.
Explain the difference between using an imported class and extending a class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
46
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 instance data and methods might you define for SportsCar that are not part of Car?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
47
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
48
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.
Consider a class named Name which has four instance data (all Strings): first, last, middle, title. Even though Name inherits the equals method from Object, it would make sense to override it. Why?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
49
Explain the difference between implementing an interface and a derived class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.