Comprehend

  • The method name and return type are mandatory in a method declaration. Even though you are not required to specify a modifier in a method declaration, the default modifier is assigned to the method, if you don’t declare one.
  • A static variable belongs to the class and not to a particular instance of the class, and therefore is initialized when the class is loaded, and before the class is instantiated.
  • Because a static method belongs to a class and not to a particular instance of the class, it cannot access the nonstatic methods and variables of the class in which it is defined.
  • An instance of an inner class can only exist in an instance of the outer class, and has direct access to all the instance variables and methods of the outer instance.
  • If you make a super call or a this call, it must be in the beginning of a constructor. That means you can make either a super call or a this call, but not both.

Look Out

  • The variable-length parameters list must appear last in the parentheses of a method and it consists of a data type, three dots, and a name, in that order.
  • A Java class cannot inherit from more than one class, but it can inherit from one class and one or more interfaces.
  • The class that inherits from an interface must provide implementation for all the methods that are declared in the interface if the class is not abstract.
  • An interface can extend another interface but it cannot implement another interface or a class.

Memorize

  • If you do not provide any constructor for a class you write, the compiler provides the default constructor for that class. If you write at least one constructor for the class, the compiler provides no constructor.
  • If you don not make a this or a super call in the beginning of a constructor, the compiler places a super() call there.
  • You use the keyword extends to write a derived class that inherits from a parent class, and use the keyword implements to write a class that inherits from an interface.
  • The methods in an interface are inherently public and abstract, and the variables in the interface are inherently public, final, and static.