Part A: class A { A(int i) {} // 1 } class B extends A {} // 2 Which of the foll
ID: 3714472 • Letter: P
Question
Part A:
class A {
A(int i) {} // 1
} class B extends A {} // 2
Which of the following statements are true? Choose 2
a. The compiler attempts to create a default constructor for class A.
b. The compiler attempts to create a default constructor for class B.
c. Compile-time error at 1.
d. Compile-time error at 2.
Part B:
class A {A() throws Exception {}} // 1
class B extends A {B() throws Exception {}} // 2
class C extends A {C() {}} // 3
Which of the following statements are true? Choose 2.
a. class A extends Object.
b. Compile-time error at 1.
c. Compile-time error at 2.
d. Compile-time error at 3.
Part C:
Which of the following modifiers CANNOT be applied to the declaration of a field? Choose 2
a. abstract
b. final
c. private
d. protected
e. public
f. transient g const
Part D:
2 class A {
3 public static void main (String[] args) {
4 Error error = new Error();
5 Exception exception = new Exception();
6 System.out.print((exception instanceof Throwable) + ",");
7 System.out.print(error instanceof Throwable);
8 }
9 }
What is the result of attempting to compile and run the program? Choose 1.
a. Prints: false,false
b. Prints: false,true
c. Prints: true,false
d. Prints: true,true
e. Compile-time error
f. Run-time error
g. None of the above
Part E:
String d = “beekeeper”;
d.substring(1,7);
d = “w” + d;
d.insert(3,”bee”);
System.out.println(d);
What is the result?
a. wbeebeekeep
b. wbeekeeper
c. wbeekeepe
d. weekeeper
e. whoneyproducer
f. Compilation fails
g. An exception is thrown
Explanation / Answer
If you post more than 1 question, as per chegg guidelines Ihave to solve only first question.
Part A: Answer : (d) Compile-time error at 2.
There is no constructor with one int argument in class B. So, when we compile the program, it shows error as a default constructor is not defined explicitly in A.
Part B: Answer : (a), (d)
Each class in Java extends Object class.
Also, the exception thrown in A must be thrown again or caught in class C.
Part C: Answer : (e) transient g const
it is not a valid declaration.
Part D: Answer : d. Prints: true,true
instanceOf is a method in Java which returns true if the object on the left side is an instance of the class on the right side. Now, Throwable is the super class of Error and Exception. SO, it prints true.