1. What is a Java program?
a) A collection of classes
b) A collection of objects talking to other objects by invoking each others methods
c) A template that describes the kinds of state and behavior that objects of its type support
2. Java components are:
a) types
b) classes
c) variables
d) objects
e) instances
f) methods
3. What is inheritance?
a) Code defined in one class can not be reused in other classes
b) Code defined in one class can be reused in other classes
c) A relationship between classes
4. What is the relationship between super-class and subclasses:
a) subclasses extend super-class
b) super-class is more abstract while subclasses are more specific
c) super-class knows about the classes that inherit from it
d) subclasses need not to declare the inheritance relationship
e) a subclass can override super-class methods to define more specific behavior
5. Which of these identifiers are legal:
a) int 3book;
b) int $3book;
c) int _3book;
d) int _$;
e) int enum;
f) int aaa#;
g) int .f;
h) int very_long_name_of_the_identifier_very_very_very_long;
i) int :b;
j) int +b;
6. Java keywords are:
a) export
b) import
c) native
d) throw
e) volatile
f) while
g) synchronized
h) swing
i) strictfp
j) transient
7. Choose valid JavaBean method signatures:
a) public void getValue(int v)
b) public void setValue(int v)
c) public boolean isMyStatus()
d) public void modifyValue(int v)
e) public void addMyListener(MyListener m)
f) public int getValue()
g) public void addXListener(MyListener m)
h) void setCustomerName(String s)
i) public void removeMyListener(MyListener m)
Access modifiers are:
- final
- public
- private
- abstract
- protected
- strictfp
If a class has a default access:
- it has a modifier private in its declaration
- it can be seen only by classes within the same package
- it has no modifier preceding it in the declaration
- any class in any package can create an instance of this class
- default access means a package-level access
Choose nonaccess modifiers:
- private
- abstract
- strictfp
- public
- protected
- final
What mix of modifiers are legal:
- public final
- strictfp final
- final abstract
- private final
- abstract private
- abstract static
Answers to questions:
Question 1: What is a Java program?
Answer: (2) A collection of objects talking to other objects by invoking each others methods.
Question 2: Java components are:
Answer: (2) classes, (3) variables, (6) methods
Question 3: What is inheritance?
Answer: (2) code defined in one class can be reused in other classes, (3) a relationship between classes
Question 4: What is the relationship between super-class and subclasses:
Answer: (1) subclasses extend super-class, (2) superclass is more abstract while subclasses are more specific, (5) a subclass can override superclass methods to define more specific behavior
Question 5: Which of these identifiers are legal:
Answer: (2) int $3book; (3)int _3book; (4) int _$; (8) int very_long_name_of_the_identifier_very_very_very_long;
Question 6: Java keywords are:
Answer: (2) import, (3) native, (4) throw, (5) volatile, (7) synchronized, (9) strictfp, (10) transient
Question 7: Choose valid JavaBean method signatures:
Answer: (2) public void setValue(int v), (3) public boolean isMyStatus(), (5) public void addMyListener(MyListener m), (6) public int getValue(), (9) public void removeMyListener(MyListener m)
Question 8: Access modifiers are:
Answer: (2) public, (3) private, (5) protected
Question 9: If a class has a default access:
Answer: (2) it can be seen only by classes within the same package, (3) it has no modifier preceding it in the declaration, (5) default access means a package-level access
Question 10 : Choose nonaccess modifiers:
Answer: (2) abstract, (3) strictfp, (6) final
Question 11: What mix of modifiers are legal:
Answer: (1) public final, (2) strictfp final, (4) private final
See Also
- - Java quiz: Object Orientation
- - Java regex by example: strings
- - Java Basic Programs: 5 Simple Examples
- - Java variable types
- - Java 9 Strings