Use the following partial classes for the next seven questions. The four classes
ID: 3672606 • Letter: U
Question
Use the following partial classes for the next seven questions. The four classes below are in the same package (and directory).
public class Class1 {
public String a;
private String b;
protected String c;
...
}
public class Class2 extends Class1 {
protected String x;
private String y;
public String z;
...
}
public class Class3 extends Class2 {
private String q;
protected String r;
public String s;
...
}
public class Class4 {
...
}
Which variables can be directly accessed from within Class1?
Select one or more:
a
b
c
x
y
z
q
r
s
Question 6
Which variables can be directly accessed from within Class2?
Select one or more:
a
b
c
x
y
z
q
r
s
Question 7
Which variables can be directly accessed from within Class3?
Select one or more:
a
b
c
x
y
z
q
r
s
Question 8
Which variables can be directly accessed from within Class4?
Select one or more:
a
b
c
x
y
z
q
r
s
Question 9
Which of the following is true about Class4?
Select one:
it has no parent class
it has one parent class
it has more than one parent class
you cannot tell anything about the parent of Class4 from the code shown
Question 10
The two classes below are in a different package (and directory) than Class1, Class2, Class3, and Class4.
public class Class5 {
...
}
public class Class6 extends Class3
...
}
Which variables can be directly accessed from within Class5?
Select one or more:
a
b
c
x
y
z
q
r
s
Question 11
Which variables can be directly accessed from within Class6?
Select one or more:
a
b
c
x
y
z
q
r
s
#12 All objects inherit the methods from the Object class. Select one: True False
#13 In a child class, you can directly access private instance variables declared in the parent class. True False
#14 Question 14
In a child class, you can directly invoke private methods declared in the parent class. Select one: True False
Question 15
Which of the following is the syntax to invoke the parent's constructor?
Select one: super followed by dot
super followed by parentheses containing arguments
super followed by dot and the superclass constructor name
none of the above
Question 16 In a child class constructor, if you do not explicitly call a parent constructor, then no parent constructor is ever called. Select one: True False
Question 17
When you overload a method, the type, order, and number of parameters must exactly match the original method.
Select one:
True
False
Question 18
When you override a method, the type, order, and number of parameters must exactly match the original method.
Select one:
True
False
Question 19
The equals method inherited from Object determines:
Select one:
whether two references have the same type.
whether two objects have the same instance variable values.
whether two references refer to the same object in memory.
whether two objects have the same instance variables.
Question 20
Declaring a method final means that
Select one:
it cannot be overloaded.
it cannot be overridden.
it cannot be accessed from outside its class.
it cannot be accessed through an invoking object.
Question 21
Consider the classes below, declared in the same package.
class A {
int a;
public A() {
a = 7;
}
}
class B extends A {
int b;
public B() {
b = 8;
}
}
Which of the following is true? Select all that apply.
Select one or more:
A reference of type B has two integer characteristics as its instance data.
b is an instance variable.
a is an instance variable
A reference of type B can be treated as a reference of type A. (B is an A)
After the constructor for class B executes, b will have the value 8.
After the constructor for class B executes, the variable a will have the value 7.
A reference of type A can be treated as a reference of type B. (A is a B)
Explanation / Answer
Mark the options of the questions starting from 1.
a, b, and c
Explanation:
a, c, x, y, and z.
Explanation:
a, c, x, z, q, r and s.
Explanation:
The correct option is 4.
Explanation:
Thus, the first three options are incorrect.
Thus, the correct option is fourth.
Explanation:
The correct option is 1.
Explanation:
Hence, the given statement is true.
The correct option is 1.
Explanation:
Hence, the given statement is false.
The correct option is 2.
Explanation:
The private methods cannot be accessible.
Hence, the given statement is false.
The correct option is 2.
Explanation:
super followed by parentheses containing arguments.
The correct option is 2.
Hence, the given statement is false.
The correct option is 2.
Explanation:
Hence, the given statement is false.
The correct option is 2.
Explanation:
Hence, the given statement is true.
The correct option is 3.
The correct option is 2.
Explanation:
Hence, the meaning of a final method is that it cannot be override.
The correct options are 2, 3, 4, 6, 7, and 8.
Explanation:
Hence, they are the instance variables.
Explanation:
Hence, the variable b contains the value 8.
Hence, the value of a becomes 7.
Explanation:
The objects of the parent class can also be treated as of child class.
Therefore, the correct syntax is as follows:
A obj = new B ();
The object type is of parent class.
Here, obj is the object is of type A.