0% found this document useful (0 votes)
13 views

Java Differences (Module 2)

1. Methods can have any name, allow modifiers, and require a return type while constructors must have the same name as the class, do not allow modifiers, and do not require a return type. Methods are executed when called by the user while constructors are executed automatically upon object creation. 2. Static members are loaded during class loading and can be accessed using the class name, while non-static members are loaded during object creation and accessed using a reference variable. 3. Overloading performs the same task in multiple ways using different arguments within the same class, while overriding changes the task itself but with the same name and arguments across classes. Constructors and some methods cannot be overridden.

Uploaded by

H ARAVIND SIVA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Java Differences (Module 2)

1. Methods can have any name, allow modifiers, and require a return type while constructors must have the same name as the class, do not allow modifiers, and do not require a return type. Methods are executed when called by the user while constructors are executed automatically upon object creation. 2. Static members are loaded during class loading and can be accessed using the class name, while non-static members are loaded during object creation and accessed using a reference variable. 3. Overloading performs the same task in multiple ways using different arguments within the same class, while overriding changes the task itself but with the same name and arguments across classes. Constructors and some methods cannot be overridden.

Uploaded by

H ARAVIND SIVA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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. known as late binding .
Once the binding decision is taken by the Once the binding decision is taken by the jvm it
compiler it can’t be changed that is why it is can be changed across the program that is why
also called static polymorphism. it is also called dynamic polymorphism.
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 bydefault static and final
It allows concrete and abstract methods Every method 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 and this()


this this()
It is a keyword used to refer the current object. It is special method used to call one constructor
from another constructor within the same class.
It can be used anywhere inside a constructor It should always be the first statement of the
and non-static method constructor body.
   
   

Difference between super and super()


super super()
It is a keyword used to refer the super class It is special method used to call super class
properties from the subclass. constructor from the subclass constructor .
It can be used anywhere inside a constructor It should always be the first statement of the
and non-static method constructor body.

You might also like