Inheriting a class gives you access to … ?
Inheriting a class gives you access to all of the public and protected methods of the class, but special rules for constructors and overriding methods must be followed or the code will not compile.
Should we provide in the child’s constructors parent class constructor ?
If the parent class doesn’t include a no-argument constructor, an explicit call to a parent constructor must be provided in the child’s constructors.
What is variable hiding (inheritance aspect) ?
When you hide a variable, you define a variable with the same name as a variable in a parent class. This creates two copies of the variable within an instance of the child class: one instance defined for the parent reference and another defi ned for the child reference.
What is the difference between overriding and hiding methods ?
Unlike overriding a method, in which a child method
replaces the parent method in calls defi ned in both the parent and child, hidden methods only replace parent methods in the calls defi ned in the child class.
What abstract class definition rules you know (instantiation, numbers of methods, modifiers, inheritance, implementation)?
What abstract method definition rules you know (scope of definition, modifiers, implementation,)?
What is interface ?
It may be helpful to think of an interface as a specialized kind of abstract class, since it shares many of the same properties and rules as an abstract class. The following is a list of rules for creating an interface, many of which you should recognize as adaptions of the rules for defining abstract classes:
What is default interface methods (purpuse and rules) ?
A default method is a method defi ned within an interface with the default keyword in which a method body is provided. Contrast default methods with “regular” methods in an interface, which are assumed to be abstract and may not have a method body.
A default method within an interface defi nes an abstract method with a default implementation. In this manner, classes have the option to override the default method if they need to, but they are not required to do so. If the class doesn’t override the method, the default implementation will be used. In this manner, the method defi nition is concrete, not abstract.
The following are the default interface method rules you need to be familiar with:
What is static interface methods ?
Java 8 also now includes support for static methods within interfaces. These methods are defined explicitly with the static keyword and function nearly identically to static methods defined in classes. In fact, there is really only one distinction between a static method in a class and an interface. A static method defined in an interface is not inherited in any classes that implement the interface.
Here are the static interface method rules you need to be familiar with:
What is called virtual method ?
A virtual method is a method in which the specific implementation is not determined until runtime. In fact, all non-final, nonstatic, and non-private Java methods are considered virtual methods, since any of them can be overridden at runtime. What makes a virtual method special in Java is that if you call a method on an object that overrides a method, you get the overridden method, even if the call to the method is on a parent reference or within the parent class.
What modifiers are implicitly applied to all interface methods ?
All interface methods are only implicitly public. Since Java 8 now includes default and static methods and they are never abstract, you cannot assume the abstract modifier will be implicitly applied to all methods by the compiler.
Can we override nonprivate static method from parent class to non-static method in the child class ?
No. For nonprivate methods in the parent class, both methods must use static
(hide) or neither should use static (override).
When null can be passed as an object value ?
Null value can always be passed as an object value, regardless of type.