I am in a process to learn the java programming ‘again’. Looking back at the basics always helps and this is what I will do in this post. It will help me to strengthen my own knowledge and may be to any reader. Pls do post any important tips if you have.
I will be very thankful to you. I wont state the definitions and all here.. simply some points (which I did not practice for long time) that I am reminding myself.
Inside Inheritance: A subclass inherits all the members from its superclass. Members here are field, methods, and nested classes. Constructors are not members, so they are not inherited by subclasses, however a subclass can invoke the constructor of its superclass.
- A subclass inherits all the public and protected members of its parent, independent of the package the subclass is in.
- Sublcass inherits package-private members of the parent, if the superclass lies in the same package as the subclass.
- a new instance method in the subclass can be created that has the same signature as the one in the superclass (overriding).
- a new static method in the subclass can be created same as the one in superclass (hiding).
- An overriding method can also return a subtype of the type returned by the overridden method. This is called a covariant return type.
- Overridden and hidden method: Version of the hidden method invoked depend from where it is invoked (superclass or subclass).
- A protected instance method in the superclass can be made public, but not private in the subclass.
- If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, there will be whole chain of constructors called, all the way back to the constructor of ‘Object’(constructor chaining).
- Methods called from constructors should generally be declared final.
Abstract classes:
- cannot be instantiated but can be subclassed.
- abstract method is declared without implementation.
- subclass of abstract class provides implementations for all of the abstract methods in its parent class. Else, the subclass must be declared abstract.
Abstract classes and interfaces:
- abstract classes can contain fields that are not static and final, and they can contain implemented methods.
- Abstract classes are most commonly subclassed by similar classes that have a lot in common (the implemented parts of the abstract class), but also have some differences (the abstract methods).
- Abstract class that implements an interface does not need to implement all of the methods of that interface.
Generics:
- Bounded Type Parameters: Useful when we want to restrict the kinds of typed that are allowed to be passed to a type parameter. To declare a bounded type parameter, list the type parameter’s name, followed by the ‘extends’ keyword, followed by its upper bound.
- Wildcard: an unknown type in generics is represented by the wildcard character “?”.
Ok!… I have just finished reading this from the Sun java tutorial trail.. and there are a lot of things unclear… I will keep updating this section when I clear my doubts.