Syvum Home Page

Home > Quiz Games > Java Programming > Print Preview

Java Programming : Classes and Keywords: Multiple Choice

Formats Info Page Worksheet / Test Paper Quiz Review

Hide all answers   View all answers   Print   Try the Quiz

Answer the following questions about classes and reserved keywords as used in the Java programming language.


1. 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
Answer: Line 1 and line 2 only
A subclass of an abstract class can also be abstract if it does not define all the abstract methods in the parent class.

2. 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
Answer: don't use any keyword at all (make it default)

3. 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
• public
• private OR protected
Answer: private OR protected


4. 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 only in the class where it is declared.
• Visible in all classes in the same package and subclasses in other packages.
Answer: Visible in all classes in the same package and subclasses in other packages.

5. 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)
Answer: (A), (D) & (E)

6. Which of the following are keywords?
(A) switch
(B) integer
(C) default
(D) boolean
(E) object
• (A) & (C)
• (B) & (C)
• (D)
• (E)
Answer: (A) & (C)

7. 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.
Answer: (B), (C) & (E)

8. 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)
Answer: (B),(C) & (D)

9. Consider the following code:
class ClassA

Will compile and run successfully
Error. ClassB does not define a no-argument constructor
Error. There is no code in the class ClassB
Error. ClassA does not define a no-argument constructor
Error. There is no code in the constructor ClassA(int x)
Answer: Error. ClassA does not define a no-argument constructor

10. A package is a collection of
classes
interfaces
editing tools
classes and interfaces
Answer: classes and interfaces

11. 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
.
(B) & (C)
(A)
(A) & (C)
(D)
Answer: (B) & (C)

12. Which of the following defines a legal abstract class?
class Vehicle {<br>
              abstract void display(); }

abstract Vehicle {<br>
              abstract void display(); }

abstract class Vehicle {<br>
              abstract void display(); }

class abstract Vehicle {<br>
              abstract void display(); }

abstract class Vehicle {<br>
              abstract void display(); {<br>
                System.out.println("Car"); }}

Answer: abstract class Vehicle {<br>
              abstract void display(); }

13. Package p1 contains the following code:
package p1;
public class Student

Test class is not available.
Class result should be declared public.
Student class is not available.
Result body is not fully defined.
Answer: Test class is not available.

14. Consider the following code:
interface Area


Interface definition is incomplete
Method compute() in interface Area should be declared public
Method compute() in class Room should be declared public
All of these
Answer: Method compute() in class Room should be declared public

15. 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)
Answer: (B) & (C)

  Try the Quiz :     Java Programming : Classes and Keywords: Multiple Choice


Contact Info © 1999-2024 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright
Previous
-
Next
-