Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 81 pages
Exam (elaborations)

Java Chapters 11, 12, and 13- Questions and Answers| Latest Update

Document preview thumbnail
Preview 4 out of 81 pages

Java Chapters 11, 12, and 13- Questions and Answers| Latest Update

Content preview

Java Chapters 11, 12, and 13- Questions and
Answers| Latest Update
1 Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a no-arg
constructor. Which of the following is correct?
A. A a = new A();
B. A a = new B();
C. B b = new A();

D. B b = new B(); ✔️✔️B. A a = new B();
D. B b = new B();


2. What is the output of running class Test?


public class Test {
public static void main(String[] args) {
new Circle9();
}
}


public abstract class GeometricObject {
protected GeometricObject() {
System.out.print("A");
}


protected GeometricObject(String color, boolean filled) {
System.out.print("B");
}

,}


public class Circle9 extends GeometricObject {
/** No-arg constructor */
public Circle9() {
this(1.0);
System.out.print("C");
}


/** Construct circle with a specified radius */
public Circle9(double radius) {
this(radius, "white", false);
System.out.print("D");
}


/** Construct a circle with specified radius, filled, and color */
public Circle9(double radius, String color, boolean filled) {
super(color, filled);
System.out.print("E");
}
}
A. ABCD
B. BACD
C. CBAE
D. AEDC

E. BEDC ✔️✔️E. BEDC

,2. The java.lang.Number and its subclasses are introduced in Chapter 11. Analyze the following
code.


Number numberRef = new Integer(0);
Double doubleRef = (Double)numberRef;
A. There is no such class named Integer. You should use the class Int.
B. The compiler detects that numberRef is not an instance of Double.
C. A runtime class casting exception occurs, since numberRef is not an instance of Double.
D. The program runs fine, since Integer is a subclass of Double.
E. You can convert an int to double, so you can cast an Integer instance to a Double instance.
✔️✔️C. A runtime class casting exception occurs, since numberRef is not an instance of Double.
4. Analyze the following code.


Number[] numberArray = new Integer[2];
numberArray[0] = new Double(1.5);
A. You cannot use Number as a data type since it is an abstract class.
B. Since each element of numberArray is of the Number type, you cannot assign an Integer
object to it.
C. Since each element of numberArray is of the Number type, you cannot assign a Double
object to it.
D. At runtime, new Integer[2] is assigned to numberArray. This makes each element of
numberArray an Integer object. So you cannot assign a Double object to it. ✔️✔️D. At runtime,
new Integer[2] is assigned to numberArray. This makes each element of numberArray an
Integer object. So you cannot assign a Double object to it.


5. Analyze the following code. Which of the following statements is correct?


public class Test {
public static void main(String[] args) {

, Number x = new Integer(3);
System.out.println(x.intValue());
System.out.println(x.compareTo(new Integer(4)));
}
}
A. The program has a compile error because an Integer instance cannot be assigned to a
Number variable.
B. The program has a compile error because intValue is an abstract method in Number.
C. The program has a compile error because x does not have the compareTo method.

D. The program compiles and runs fine. ✔️✔️C. The program has a compile error because x does
not have the compareTo method.


6. Analyze the following code. Which of the following statements is correct?


public class Test {
public static void main(String[] args) {
Number x = new Integer(3);
System.out.println(x.intValue());
System.out.println((Integer)x.compareTo(new Integer(4)));
}
}
A. The program has a compile error because an Integer instance cannot be assigned to a
Number variable.
B. The program has a compile error because intValue is an abstract method in Number.
C. The program has a compile error because x cannot be cast into Integer.
D. The program has a compile error because the member access operator (.) is executed before
the casting operator.

E. The program compiles and runs fine. ✔️✔️D. The program has a compile error because the
member access operator (.) is executed before the casting operator.

Document information

Uploaded on
March 21, 2025
Number of pages
81
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$15.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
KateJones
4.8
(12)
Sold
31
Followers
0
Items
5707
Last sold
1 week ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions