1. What is encapsulation:
a) the ability to make changes in your implementation without breaking the code of others
b) keep instance variables accessible foe everyone
c) create getters and setters rather then give direct access to instance variables
2. IS-A relationship:
a) based on class inheritance or interface implementation
b) expresses through the keywords import and extends
c) expresses through the keywords extends and implements
d) if Car extends Vehicle it means that Car IS-A Vehicle
e) if(Foo instanceof Bar) is true that Foo IS-A Bar
3. HAS-A relationship:
a) based on usage
b) A HAS-A B if code in class A has a reference to an instance of class B
c) a superclass must be extended
d) give classes opportunity to be specialists
4. Polymorphism:
a) Any Java object that can pass more than one HAS-A test can be considered polymorphic
b) Any Java object that can pass more than one IS-A test can be considered polymorphic
5. Polymorphic method invocations apply only to
a) variables
b) instance methods
c) static methods
d) objects
e) classes
6. What is true for method overriding
a) if a method inherits from a superclass, you have the opportunity to override the method
b) a final method must be overriden
c) the concrete sublass overrides the abstract methods of the superclass
d) abstract methods are methods that you cannot override
7. What are the rules for overriding a method:
a) the argument list must exactly match that of the overriden method
b) the access level must be more restrictive than the overriden method’s
c) the access level can be less restrictive than that of the overriden method
d) the overriding method must throw new or broader exceptions than the overriden method
e) the overriding method can throw narrower or fewer exceptions
f) you must override methods marked static or final
g) if a method can’t be inherited, you cannot override it
8. What are legal overrides of the class Animal {public void eat() {} }
a) private void eat() {}
b) public void eat() {}
c) public void eat throws Exception {}
d) public void eat(int s) {}
e) public String eat() {}
9. What is the difference between overloaded and overriden methods:
a) overloaded methods let us reuse the same method name in a class but with different arguments
b) overriden methods let us reuse the same method name in a class but with different arguments
c) there is no difference
10. What is true about overloaded methods:
a) they must change the argument list
b) they cannot change the return type
c) they can change the access modifier
d) they cannot declare new or broader checked exceptions
Answers to questions:
Question 1: What is encapsulation:
Answer: a, c
Question 2: IS-A relationship:
Answer: a, c, d, e
Question 3: HAS-A relationship:
Answer: a, b, d
Question 4: Polymorphism:
Answer: b
Question 5: Polymorphic method invocations apply only to
Answer: b
Question 6: What is true for method overriding
Answer: a, c
Question 7: What are the rules for overriding a method:
Answer: a, c, e, g
Question 8: What are legal overrides of the class Animal {public void eat() {} }
Answer: b
Question 9: What is the difference between overloaded and overridden methods:
Answer: a
Question 10: What is true about overloaded methods:
Answer: a, c
See Also
- Java quiz: Declarations and Access
- Java regex by example: strings
- Java Basic Programs: 5 Simple Examples
- Java variable types
- Java 9 Strings