Questions and Answers
A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final.
True
A functional interface is simply an interface that has one abstract method.
True
An abstract class is not instantiated, but serves as a superclass for other classes.
True
All methods in an abstract class must also be declared abstract.
Signup and view all the answers
Every class has a toString method and an equals method inherited from the Object class.
Signup and view all the answers
Every class is either directly or indirectly derived from the Object class.
Signup and view all the answers
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.
Signup and view all the answers
If two methods in the same class have the same name but different signatures, the second overrides the first.
Signup and view all the answers
Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.
Signup and view all the answers
In an inheritance relationship, the subclass constructor always executes before the superclass constructor.
Signup and view all the answers
It is not possible for a superclass to call a subclass's method.
Signup and view all the answers
Private members of the superclass cannot be accessed by the subclass.
Signup and view all the answers
When a subclass extends a superclass, the public members of the superclass become public members of the subclass.
Signup and view all the answers
When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface.
Signup and view all the answers
A subclass can directly access:
Signup and view all the answers
A subclass may call an overridden superclass method by:
Signup and view all the answers
All fields declared in an interface:
Signup and view all the answers
An anonymous inner class must:
Signup and view all the answers
Given the following code, which of the following is TRUE? public class ClassB implements ClassA{}
Signup and view all the answers
If a class contains an abstract method:
Signup and view all the answers
If a superclass does not have a default constructor or a no-arg constructor:
Signup and view all the answers
Study Notes
Compiler Errors and Variables
- Anonymous inner classes can use variables only if they are final or effectively final. Using non-final variables will lead to compiler errors.
Functional Interfaces
- A functional interface is defined as an interface with exactly one abstract method.
Abstract Classes
- Abstract classes cannot be instantiated and serve as a foundation for derived classes.
- Not all methods in an abstract class need to be declared as abstract; some can have a concrete implementation.
Object Class Methods
- Every Java class inherits a
toString
method and anequals
method from theObject
class. - All classes in Java are ultimately derived from the
Object
class.
Method Overloading and Overriding
- If a method in a subclass shares the same signature with a superclass method, it overrides, not overloads, the superclass method.
- Overloading occurs when methods within the same class share names but have different signatures, while overriding represents method redefinition in subclasses.
Inheritance Relationships
- Inheritance features a superclass (general class) and a subclass (specialized class), opposite to the incorrect assertion that a subclass serves as a general class.
- The superclass constructor executes before the subclass constructor in an inheritance hierarchy.
Access Modifiers in Inheritance
- Superclass methods cannot call subclass methods directly.
- Private members in a superclass are inaccessible to subclasses.
- Public members of a superclass become public members in the subclass.
Interface Variables and Methods
- When an interface variable references an object, not all methods from the implementing class can be called; only those defined by the interface can be accessed.
- Interface variables are inherently final and static, meaning they cannot be changed once initialized.
Inner Classes
- Anonymous inner classes must either extend another class or implement an interface.
Class Implementation and Inheritance
- If a class implements an interface (e.g.,
public class ClassB implements ClassA{}
), it is required to override every abstract method defined in that interface. - Classes containing abstract methods must define those methods with only a header, omitting the implementation details.
Constructor Behavior
- A subclass inheriting from a superclass without a default constructor must explicitly call one of the available constructors in the superclass to ensure proper instantiation.
Summary of Public Access
- A subclass has access to only the public and protected members of its superclass but cannot access private members.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of Java concepts with this quiz covering chapters 10 through 16, including compiler errors and functional interfaces. Designed for students to review key definitions and true/false statements related to Java's advanced features. Perfect for a final exam preparation or a quick revision session.