- Checked & unchecked exception are two type of Exception.
- Checked exception are those exception which are subtype of Exception class but excluding classes which extends Runtime exception.
- Subtype of Error and Runtime Exceptions comes under unchecked Exception.
- Finally block will always be invoked in all condition.
- System.exit() is the only way when finally block will not get executed coz in that case JVM will shut down.
- Custom Exception can also be created by extending Exception class.
- Catch block should be order in the form of most specific to most general. Otherwise compiler will complain for unreachable code.
:: Overriding Cheatsheet
Inner Class Cheat sheet for Quick Revision
- Inner class is member of enclosing class.
- Outer class reference is required to initiate inner class.
- Inner class are of 4 type.
- Inner classes defined within method are method local inner class.
- Method local inner class can not access method local variable.
- Final & Abstract are the only modifiers available to method local inner class.
- Ananymous inner class don’t have any name.
- Inner classes having Static modifier are known as Static inner class.
- Static nested class can not access non static member of outer class.
- Constructor is invoked when a new object is created.
- Constructor’s can also be overloaded but it can not be overridden.
- Every class has at least one constructor. If user doesn’t provide any JVM will provide a default no arg constructor.
- Abstract class also has constructor.
- Constructor must have the same name as class.
- Constructor can’t have a return type.
- If a method with the same name as class has return type will be treated as normal member method and not constructor.
- Constructor can have any access modifier(All).
- Default constructor is a no arg constructor which calls the no arg constructor of super class. In case super class doesn’t have any no arg constructor then it will throw a run time exception.
- In case where a class has default constructor, its super class needs to have a no arg constructor.
- First statement of a constructor can be either this or super but can not be both at the same time.
- If coder doesn’t write any this or super call then compiler will add a call to super.
- Instance member can be accessible only after the super constructor runs.
- Interfaces do not have constructors.
- Constructor are not inherited. Hence can not be overridden.
- Constructor can not be directly invoked. It will be invoked(Implicitly) when a new object is created or a call by other constructor.