0% found this document useful (0 votes)
12 views3 pages

Notes - Class, Obj, Constructor

Uploaded by

samboxer985
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Notes - Class, Obj, Constructor

Uploaded by

samboxer985
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Class – A class is a set of objects which shares common behavior and common properties.

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.

Properties of Java class ---

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

// program of class and object


class arsh

void abc()

System.out.println(" hellllo ");

void sap()

System.out.println(" how r u ");

class manjot

public static void main(String args[])

arsh obj = new arsh();

obj.sap();

obj.abc();

}
Class is a blueprint or
1) Object is an instance of a class. template from which objects are
created.

Object is a real world


entity such as pen, laptop, Class is a group of similar
2)
mobile, bed, keyboard, mouse, objects.
chair etc.

3) Object is a physical entity. Class is a logical entity.

Object is created through new Class is declared using class


4) keyword mainly e.g. keyword e.g.
Student s1=new Student(); class Student{}

Object is created many


5) Class is declared once.
times as per requirement.

Object allocates memory when Class doesn't allocated


6)
it is created. memory when it is 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

1. Default Constructor Program –


//program of default constructer
class deepak
{
deepak() //constructer
{
System.out.println("helo how r u");
}
}
class ritu1
{
public static void main(String args[])
{
deepak obj=new deepak(); //object making
}
}

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();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy