The basic Java programming tips and rules
1) If one class appears to be extending the other with the defined method, the method itself might be overridden and get the same name in the final list or arguments.
2) Any method you’re trying to define within the base class shall stay visible. If it will not be this way, the method while being derived might not be considered overridden version. Sometimes it may be even treated the way the normal method usually is.
3) If you’re working with the name of method and arguments list, you shall perform the same for overriding and overridden methods. When you come to the return type, do not hesitate to use the co-variant. In case the return method reached the super-class and appeared to be Map, the return one shall be HashMap.
4) For the overriding method the access shall have the following specifier. It shall not have more limits then some other overriden method of this class. In other words for the specifier in the base class method that is protected, access specifier created for derived class method may be protected or public, but not private of default. The following specifiers go in the raw of procetcion performed: public, protected, default, private.
5) If you’re choosing the exceptions for the definer class, make it the same or the one of the sub-class. For example, in case the IOException is specified in the base class method created in the throws clause, then the other method of the derived class may be defined as FileNotFoundException, or even IOException but in no case Exception.
Java programming tips suitable for overriding methods while working in Java
1) If you see the base class or interface version being generic in nature, feel free to opt for override;
2) To increase the links in-between the classes perform the overriding or inheritance in the form of methods judiciously;
3) If you create the internal reference of the base made in interface or class type, you will invoke some of the overridden methods. In this case you may refer to any of the derived class objects. By this you will easily code the generalization and create not so many references.

Leave a Comment