2. Class
• Class is a logical entity because when we are creating a class then
memory will not be created for a class.
• Class is a collection of data members, constructors, methods and
blocks.
4. Objects
• Object is a physical entity because when we are creating object then
memory will be allocated for object.
• Object is created with the help of new keyword.
6. Constructors in Java
• In Java, a constructor is a block of codes similar to the method.
• It is called when object is created.
• At the time of calling constructor, memory for the object is allocated
in the memory.
8. Rules for creating Java constructor
• Constructor name must be the same as its class name.
• A Java constructor cannot be abstract, static, final, and synchronized
9. Types of Java Constructors
• There are 3 Types of constructors.
• Default Constructor.
• No-argument Constructor.
• Parameterized Constructor.
10. 1. Default Constructor.
• If there is no constructor in a class, compiler automatically creates a
default constructor.
18. Difference between constructor and method
in Java
Constructor Method
A Constructor is called implicitly by the
system.
A Method is called by the programmer.
A Constructor is called when a object is
created using the keyword new.
A Method is called through method calls.
A Constructor’s name must be same as
the name of the class.
A Method’s name can be anything.
A Constructor doesn’t have a return type. A Method must have a return type.
19. Ways to initialize object:
• Initializing an object means storing data into the object.
• There are 3 ways to initialize object in Java.
• By reference variable
• By method
• By constructor