Chapter 7: Beyond Classes Flashcards
Anonymous classes can be declared static?
False
Anonymous classes always have an implicit reference to their enclosing class?
True
Anonymous classes are a type of nested class that can be static?
False
Since anonymous classes cannot be static, they must be associated with an instance of the enclosing class?
True
The keyword “static” can be used when defining anonymous classes?
False
Interface variables in Java are public, static, and final by default.
True
Interfaces in Java are required to define at least one method.
False: Interfaces can be empty, and the compiler automatically treats them as abstract even without method definitions.
An interface can be instantiated directly
False: Interfaces cannot be instantiated because they only provide method signatures without implementations.
Interfaces are implicitly considered abstract, even without the abstract keyword.
True
Interfaces can be marked as final in Java.
False: Interfaces cannot be final, as final would prevent implementation, defeating their purpose.
In Java 17, if a class inherits two interfaces with the same default method signature, it must override the method. (True/False) If false, why?
True
A class can inherit conflicting default methods from multiple interfaces without requiring an override. (True/False) If false, why?
False – The compiler enforces overriding to resolve ambiguity in method implementation.
The syntax to access an inherited default method is <interface>.super.<method>. (True/False) If false, why?</method></interface>
True
In Java 17, a class can directly call a default method from an interface without specifying the interface name. (True/False) If false, why?
False – It must use <interface>.super.<method> to specify the source interface.</method></interface>
Default methods in interfaces cannot be overridden by implementing classes. (True/False) If false, why?
False – Implementing classes can override default methods to provide custom behavior.
An interface can extend multiple interfaces using the extends keyword.
True
A class can extend multiple interfaces.
False – A class implements interfaces, but it can extend only one class.
Interfaces are initialized as part of a class hierarchy.
False – Interfaces do not have constructors and are not part of instance initialization.
A class can extend an interface.
False – A class can only implement an interface, not extend it.
An interface can implement another interface.
False – An interface can extend another interface, but it cannot implement one.
A method that properly overrides inherited methods can use covariant return types.
True
Interfaces are implicitly abstract.
True
Interface variables are implicitly public, static, and final.
True
If a method or variable is marked with a conflicting modifier, the compiler applies the public modifier without conflict.
The compiler detects a conflict and generates an error.