Notes - Class, Obj, Constructor
Notes - Class, Obj, Constructor
It is a user defined
prototype from which objects are created For example – Student is a class while particular student named Ravi is an
object.
1. Class is not a real world entity, it is just a template from which objects are created.
2. Class does not occupy memory
3. Class is a group of variables of different data type and a group of methods.
Class contain
1. Data member like int a
2. Method like void display()
3. Constructor
4. Nested class ( mean class under class)
Java Objects - An object is a basic unit of object oriented programming and represents real-life entities. Objects are
the instances of class that are created to use the attributes and methods of a class
void abc()
void sap()
class manjot
obj.sap();
obj.abc();
}
Class is a blueprint or
1) Object is an instance of a class. template from which objects are
created.
Constructor – A Constructor is a block of codes similar to the method. It is called when an instance of the
class is created. At the time of calling constructor, memory for object is allocated in the memory. It is a
special type of method which is used to initialize the object using new() keyword.It calls default constructor if
there is no constructor available in the class.
Types of Constructor –
1. Default Constructor
2. Parameterized Constructor
2. Parameterized Constructor –
// Program of Parameterized Constructer
class port
{
int number1,number2 = 123;
port(int a)
{
number1=a;
}
void operator()
{
System.out.println(number1+number2);
}
}
class paracons
{
public static void main(String args[])
{
port obj=new port(12);
obj.operator();
}
}