Class/Interface Fundementals


PROTECTED – from another package
1. Inherited — yes
2. instance of inherited class (in same class) – no, static yes
3. instance of this class (in same class) – yes, static yes
4. in another class – no, static yes

Top-level modifier: public or no modifier (package private)


– same signature (can’t have subtypes)
– parameter list must be exactly the same
– access modifier must be same or more accessible
– return type must be same or more restrictive – covariant return type
– checked exception must be same or more restrictive
– can`t override static methods
– methods mustn’t be static – hiding
– can’t override final methods
When multiple overloaded methods are present:
– exact match type
– matching superclass type
– converting to larger primitive
– boxing
– varargs

Abstract Methods And Classes

– may or may not include abstract methods, but abstract methods can`t be in non-abstract class
– must have abstract keyword (otherwise requires body)
– may include default or static methods, or no methods at all
– unlike in interface you can declare fields that are not static and final, and define public, protected, and private concrete methods, with interfaces all fields are automatically public, static and final, and all methods public and abstract
Illegal modifier for the interface field interface_.z; only public, static & final are permitted
– may have static fields and methods
– abstract method – no body and ends with ;


– implicitly public, static, and final (fields must be initialized)
– can contain only constant declarations
– method cannot hide instance methods from Object
– default methods enable you to add methods that accept lambda expressions as parameters to existing interfaces
– default methods can be overriden to abstract
– concrete methods in classes implementing interface must be public –visibility can`t be reduced
– implements clause follows the extends clause
– two default methods rule
– interface can`t extend class, interface can extend multiple interface

Abstract class is same as class but…
– can`t be instantiated
– can have abstract methods
– are same as abstract classes but can only declare public methods and constants