Java Core
Java Core
Java Core
https://www.javatpoint.com/difference-between-throw-and-throws-in-java
1) If super class method has not declared any exception using throws
clause then subclass overridden method can't declare any checked
exception but it can declare unchecked exception with the throws clause.
2) If super class method has declared a checked exception using throws clause
then subclass overridden method can do one of the three things.
The throws keyword is used in the function signature. It is used when the function
has some statements that can lead to exceptions.
Interface::
Dafault method::
Block is used to initialize the instance data member. It run each time when object
of the class is created.
**Instance intializer block is invoked at the time of object creation. The java
compiler copies the instance initializer block in the constructor after the first
statement super(). So firstly, constructor is invoked.
** The instance initializer block comes in the order in which they appear.
class A{
A()
{
super();
{Instance block}
{constructor code}
}
}
***If using Set with primitive, it will not save duplicate, but if we use non
primitve, it will save duplicates also, so needto override hashcode and equals
method.
** method hiding
Method hiding can be defined as, "if a subclass defines a static method with the
same signature as a static method in the super class, in such a case, the method in
the subclass hides the one in the superclass." The mechanism is known as method
hiding. It happens because static methods are resolved at compile time.