Question | Answer |
Which of the following statements about abstract methods/classes in Java are true? 1. An abstract class cannot be instantiated. 2. Constructors cannot be abstract. 3. A subclass of an abstract class must defined the abstract methods. 4. Static methods may be declared abstract. Line 1, line 2 and line 3 only
Line 1 only
Line 1 and line 2 only Line 2 only
All are true
| Line 1 and line 2 only |
Which keyword can protect a class in a package from accessibility by the classes outside the package? private
don't use any keyword at all (make it default) protected
final
| don't use any keyword at all (make it default) |
We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this? private
protected
private OR protected public
| private OR protected |
The use of protected keyword to a member in a class will restrict its visibility as follows: Visible only in the class and its subclass in the same package.
Visible only inside the package.
Visible in all classes in the same package and subclasses in other packages. Visible only in the class where it is declared.
| Visible in all classes in the same package and subclasses in other packages. |
Which of the following are not keywords? (A) NULL (B) implements (C) protected (D) extended (E) string (A), (D) & (E) (C), (D) & (E)
(D) & (E)
(D)
| (A), (D) & (E) |
Which of the following are keywords? (A) switch (B) integer (C) default (D) boolean (E) object (B) & (C)
(D)
(A) & (C) (E)
| (A) & (C) |
Which of the following keywords are used to control access to a class member? (A) default (B) abstract (C) protected (D) interface (E) public (C) & (E)
(B), (C) & (E) (A), (C) & (E)
All of these.
| (B), (C) & (E) |
The keywords reserved but not used in the initial version of Java are: (A) union (B) const (C) inner (D) goto (E) boolean (F) synchronized (C) & (E)
(A), (C) & (E)
All of these.
(B),(C) & (D)
| (B),(C) & (D) |
Consider the following code: class ClassA
Will compile and run successfully
Error. ClassA does not define a no-argument constructor Error. ClassB does not define a no-argument constructor
Error. There is no code in the class ClassB
Error. There is no code in the constructor ClassA(int x)
| Error. ClassA does not define a no-argument constructor |
A package is a collection of classes
interfaces
editing tools
classes and interfaces
| classes and interfaces |
Which of the following statements are true? (A) An abstract class may not have any final methods. (B) A final class may not have any abstract methods. (C) An inner class may be declared with any accessibility keyword. (D) Transient variables must be static. (A)
(B) & (C) (A) & (C)
(D)
| (B) & (C) |
Which of the following defines a legal abstract class? class Vehicle {<br> abstract void display(); }
abstract class Vehicle {<br> abstract void display(); } abstract Vehicle {<br> abstract void display(); }
class abstract Vehicle {<br> abstract void display(); }
abstract class Vehicle {<br> abstract void display(); {<br> System.out.println("Car"); }}
| abstract class Vehicle {<br> abstract void display(); } |
Package p1 contains the following code: package p1; public class Student Class result should be declared public.
Test class is not available. Student class is not available.
Result body is not fully defined.
| Test class is not available. |
Consider the following code: interface Area
Interface definition is incomplete
Method compute() in interface Area should be declared public
All of these
Method compute() in class Room should be declared public
| Method compute() in class Room should be declared public |
The concept of multiple inheritance is implemented in Java by (A) extending two or more classes (B) extending one class and implementing one or more interfaces (C) implementing two or more interfaces (D) all of these (A)
(A) & (C)
(B) & (C) (D)
| (B) & (C) |