Which base class members AREN’T inherited by a class?
* constructors of the base class
Can a base class without abstract methods be defined as an abstract class?
Yes
Can you ever create objects of an abstract class?
No
What happens if a derived class doesn’t implement all the abstract methods of its base class?
It will fail to compile UNLESS it is defined as an abstract class.
What are the implicit modifiers of an interface and its components?
* interface variables: public, static, final.
What is the explicit way of writing
interface Cheetah{
double distance = 21;
int height(); }interface Cheetah{
public static final double distance = 21;
public abstract int height(); }
Can interfaces include class names?
No, an interface can never extend any class.
Can you define a top-level, protected Interface?
No, only possibilities are
• public
• no modifier (default access)
[ But inner or nested types can have any access level ]
Which, if any, lines fail to compile,
2+3: “illegal combination of modifiers: public and private” All members of an interface are inherently public.
What are valid, non-access modifiers for an interface?
* strictfp
Which of the following compile successfully?
None of them. Valid top-level interface modifiers include
• no modifier, public (access)
• abstract, strictfp (nonaccess)
What kinds of methods can be defined in an interface?
What kind of method is eatPotato()?
interface Interviewer { void eatPotato(); }
• abstract
Which of these is a valid default method?
How can a developer add methods to an interface without breaking existing implementations?
Only by adding default methods. When a class implements and interface with abstract methods, the class must implement all of the methods or else it won’t compile.
Given
interface Interviewer {
abstract void conductInterview();
default void submitInterviewerStatus() {
System.out.println(“Accept”);
}
static void bookConferenceRoom(LocalDateTime dateTime, int duration) {
System.out.println(“Interview scheduled on:” + dateTime);
System.out.println(“Book conference room for: “ + duration + “ hrs”);
}
}
Which of the following lines, if any, fail to compile?
5, 7: A static method in an interface can’t be called using a reference variable, it must be called using the interface name.
[Note: but it is fine to call a static variable defined in a CLASS using either the reference variables or by the name of the class.]
Which of the following compile successfully?
1. interface Interviewer {
abstract int interviewConducted();
}
class Manager implements Interviewer {}
2. interface Interviewer {
abstract int interviewConducted();
}
class Manager implements Interviewer {
int interviewConducted();
return 1;
}
3. interface Interviewer {
abstract Object interviewConducted();
}
class Manager implements Interviewer {
public String interviewConducted() {
return null;
}
}
4. interface Interviewer {
abstract Object interviewConducted();
}
class Manager implements Interviewer {
public Integer interviewConducted() {
return 1;
}
}