Difference between methods and constructors
Methods Constructors
It can have any name It should have the same name as that of the class name
It will allow modifiers Modifiers are not allowed
Return type is mandatory Return type is not allowed
It will execute when called by the user It will execute automatically when we create object
It is used to write business logics It is used to initialize the non-static variables
Difference between static and non-static
Static Non-static
We can create a static member by using static We can create a non-static member without
keyword using static keyword
Static members will be loaded in the class Non-static members will loaded in the heap
memory during class loading time memory during object creation
Static members can be accessed by using the Non-static members can be accessed with the
class name. help of reference variable
Difference between Overloading and Overriding
Overloading Overriding
Performing one task in multiple ways in known as Changing the task itself is known as
Overloading Overriding
While overloading method name must be same but While overriding both the method name and
the arguments must be different arguments must be same
Constructors can be overloaded We can't override constructors
Static, private and final methods can be overloaded We can't override static, private and final
method
It can take place within the same class It must happen across different class
Is-a relationship is not required Is-a relationship is mandatory
It is an example for compile time polymorphism It is an example for runtime polymorphism
Difference between Compile Time Polymorphism and Run Time Polymorphism
Compile Time Polymorphism Run Time Polymorphism
It can be achieved by using method overloading It can be achieved by using method overriding
Binding decision is taken by the compiler Binding decision is taken by the JVM
Compiler takes the decision based on the JVM takes the decision based on the object
arguments type(reference variable)
Since binding takes place during the compile Since binding takes place during the run time it
time it known as early binding or static binding known as late binding or dynamic binding
Difference between Abstract class and Interface
Abstract class Interface
It is not a pure abstract because it allows It is pure abstract because it allows only
concrete method abstract method
Constructors are allowed Constructors are not allowed
Multiple inheritance can't be achieved Multiple inheritance can be achieved
Implementation is provided in subclass by using Implementation is provided in implementation
extends keyword class by using implements keyword
It allows both static and non-static variable Every variable is by default static and final
It allows concrete and static methods Every methods is by default public and abstract
It is recommended to use when we know the It is recommended to use when we don't know
partial implementation of an application any implementation of an application
Difference between this keyword and super keyword
this super
It is used to refer to the current object It is used to refer to the super class properties
from the subclass
It can be used anywhere inside a constructor It can be used anywhere inside a constructor and
and non-static method non-static method
Difference between this() and super()
this() super()
It is used to perform constructor calling It is used to perform constructor chaining
It can be used inside the constructor and it It can be used inside the constructor and it
should be the first statement of the constructor should be the first statement of the constructor
body body