Java Declaration 5 Min Drill

  • Arrays are objects in Java.
  • In Java an array is a collection of ordered primitives, object references.
  • It is never legal to include the size of an array in the declaration.
  • An array of objects can hold any object that passes the IS-A (or instanceof) test for the declared type of the array. e.g, if Circle extends Shape, then a Circle object can go into an Shape array.
  • A class is usually described as the template or blueprint from which the object is actually made.
  • A class can also be defined as new data type.
  • An instance of a class is an object.
  • In Java the methods are similar to functions in C/C++.
  • An abstract classes cannot be instantiated. If you define one method as abstract in a class the class must be defined as abstract.
  • Abstract methods does not have method implementation (i.e. method bodies), the implementation is provided by the subclasses.
  • In Java constructors are used to initialize the object. The name of the constructor is the same name as the class name.
  • If you define one non-default constructor in any given class, then the default constructor will not be provided by the compiler.
  • A source code file can have only one public class.
  • If the source file contains a public class, the filename must match the public class name.
  • A file can have only one package statement, but it can have multiple imports.
  • The package statement (if any) must be the first (noncomment) line in a source file.
  • The import statements (if any) must come after the package and before the class declaration.
  • If there is no package statement, import statements must be the first (noncomment) statements in the source file.
  • A file can have more than one nonpublic class.
  • Files with no public classes have no naming restrictions.
  • An interface can have only abstract methods, no concrete methods allowed (upto Java 1.7).
  • Interface methods are by default public and abstract—explicit declaration of these modifiers is optional.
  • Interfaces can have constants, which are always implicitly public, static, and final.
  • Interface constant declarations of public, static, and final are optional in any combination.
  • Class implementing an interface can itself be abstract.
  • An abstract implementing class does not have to implement the interface methods (but the first concrete subclass must).
  • Class can extend only one class, but it can implement many interfaces.
  • Interfaces can extend one or more other interfaces.
  • A subclass can inherit a member of its superclass.
  • this. always refers to the currently executing object.