Which statement is true?
A.
Both p and s are accessible by obj.
B.
Only s is accessible by obj.
C.
Both r and s are accessible by obj.
D.
p, r, and s are accessible by obj.
Only s is accessible by obj.
Given the code fragment:
What is the result?
A.
Found Red
Found Default
B.
Found Teal
C.
Found Red
Found Blue
Found Teal
D.
Found Red
Found Blue
Found Teal
Found Default
E. Found Default
Found Teal
Which statement is/are true?
I. Default constructor only contains "super();" call.
II. We can't use any access modifier with a constructor.
III. A constructor should not have a return type.
A.
Only I.
B.
Only II.
C.
Only I and II.
D.
Only I and III.
E.
AIL
Only I and III.
Statement I is correct as the default constructor only contains super0 call
Statement II is incorrect as we can use any access modifier with a constructor.
Statement III is correct as constructor can't have return type, even void.
So option D is correct.
httpsy/docs.oracle.com/javase/tutorial/iava/javaOO/construaors.html
Given:
public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new
SampleClass();
sc = asc;
System.out.println("sc: " + sc.getClass());
System.out.println("asc: " + asc.getClass());
}}
class AnotherSampleClass extends SampleClass {
}
What is the result?
A.
sc: class Object
asc: class AnotherSampleClass
B.
sc: class SampleClass
asc: class AnotherSampleClass
C.
sc: class AnotherSampleClass
asc: class SampleClass
D.
sc: class AnotherSampleClass
asc: class AnotherSampleClass
sc: class AnotherSampleClass
asc: class AnotherSampleClass
Given:
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
Option B
Option C
When an abstract class is subclassed, the subclass usually provides
implementations for all of the abstract methods in its parent class (C). However, if it does
not, then the subclass must also be declared abstract (B).
Note: An abstract class is a class that is declared abstract—it may or may not include
abstract methods. Abstract classes cannot be instantiated, but they can be subclassed
Page 9 out of 48 Pages |
Previous |