SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Classes
&
Objects
In JAVA
-M Vishnuvardhan,
Dept. of Computer Science,
SSBN Degree College, ATP
SSBN Degree College, ATP M Vishnuvardhan
Introduction
In real world we can find many objects like car, student, … All these
objects have state and behavior. To represent these real world entitles
Objects are used in software. Object is software representation of real
life thing. In order to create an object first wee need to describe how
the object should be.
SSBN Degree College, ATP M Vishnuvardhan
Class
A class is a template which describes an Entity or Object.
i.e., A class is a blueprint of the object. Using a class it is possible to
create multiple objects
A class describes an entity in two ways
1.Properties of class (gives characteristics)
2.Behavior(functionality)
Eg: Student --- RollNo, Name, gender ….
--- getAdmission, writeExam, getResult
SSBN Degree College, ATP M Vishnuvardhan
Representation of Class
Syntax:
class ClassName
{
declaration of properties
definations of methods
}
class Student
{
int rollNo;
String name;
void getAdmission()
{ ================ }
}
SSBN Degree College, ATP M Vishnuvardhan
Class - Properties
These are special variables used to describe the characteristics of an
Object. These are also called as attributes/ data members / data.
Syntax :
<<access Specifier>> dataType PropertyName;
Eg:
int rollNo;
String name;
Access Specifier controls the availability and accessibility of member
of a class in different parts of the program.
Eg:- public, private, protected, private protected & default.
For Every member access Specifier need to specified separately
SSBN Degree College, ATP M Vishnuvardhan
Class - Methods
These are functions used to describe the behavior of an Object.
These are also called as member functions/ code.
Syntax :
<<access Specifier>> returnType methodName(<<arguments>>)
{
======= // body of the method (method definition)
}
Eg: void getAdmisssion()
{
=====
}
void printData(int x)
{
=====
}
SSBN Degree College, ATP M Vishnuvardhan
Class - Methods
class Box
{
int length, width;
double area, perimeter;
void calculate()
{
area=length*width;
perimeter=2*(length+width);
}
void printData()
{
System.out.println(“Length:”+length);
System.out.println(“Width:”+width);
System.out.println(“Area:”+area);
System.out.println(“Perimeter:”+perimeter);
}
}
SSBN Degree College, ATP M Vishnuvardhan
Properties of Constructors
» A constructor cannot be called like a ordinary method.
» A constructor is called only once in the life time of an object.
» A constructor is always invoked at the time of creation of object
with the help of new keyword.
» Every class must have a constructor. Without constructor object
creation is not possible.
» If a constructor is not defined for a class the compiler provides a
constructor for the class.
SSBN Degree College, ATP M Vishnuvardhan
Constructor vs. method
Java Constructor Java Method
Constructor is used to initialize the
state of an object.
Method is used to expose
behaviour of an object.
Constructor must not have return
type.
Method must have return type.
Constructor is invoked implicitly. Method is invoked explicitly.
The java compiler provides a default
constructor if you don't have any
constructor.
Method is not provided by
compiler in any case.
Constructor name must be same as
the class name.
Method name may or may not
be same as class name.
SSBN Degree College, ATP M Vishnuvardhan
Types of Constructors
Constructors in java can be of two types
»Default Constructor:
Constructor provided by the compiler is called as default
constructor or a constructor with out parameters is also called as
default constructor
»Parameterized Constructor:
Constructor with parameters is called as parameterized
constructors.
SSBN Degree College, ATP M Vishnuvardhan
Types of Constructors
Constructors in java can be of two types
»Default Constructor:
Constructor provided by the compiler is called as default
constructor or a constructor with out parameters is also called as
default constructor
»Parameterized Constructor:
Constructor with parameters is called as parameterized
constructors.
SSBN Degree College, ATP M Vishnuvardhan
Questions

More Related Content

PPTX
Java class,object,method introduction
PPTX
Type casting in java
PPTX
Strings in Java
PPTX
Oop c++class(final).ppt
PDF
JavaScript - Chapter 8 - Objects
PPTX
Java constructors
PPTX
Inheritance in java
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Java class,object,method introduction
Type casting in java
Strings in Java
Oop c++class(final).ppt
JavaScript - Chapter 8 - Objects
Java constructors
Inheritance in java
Chapter 02: Classes Objects and Methods Java by Tushar B Kute

What's hot (20)

PDF
Function overloading ppt
PPTX
Polymorphism in java
PPTX
Interface in java
PPTX
Data types in java
PPTX
Introduction to Java Strings, By Kavita Ganesan
PPT
PPTX
Introduction to java
PPTX
Core java complete ppt(note)
PPTX
Core Java
PPT
Java tutorial PPT
PPTX
Data Types, Variables, and Operators
PPTX
Inheritance in java
PPTX
Inheritance in JAVA PPT
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Static keyword ppt
PPT
Object and class
PPTX
Virtual base class
PPSX
Data Types & Variables in JAVA
Function overloading ppt
Polymorphism in java
Interface in java
Data types in java
Introduction to Java Strings, By Kavita Ganesan
Introduction to java
Core java complete ppt(note)
Core Java
Java tutorial PPT
Data Types, Variables, and Operators
Inheritance in java
Inheritance in JAVA PPT
Basic Concepts of OOPs (Object Oriented Programming in Java)
Static keyword ppt
Object and class
Virtual base class
Data Types & Variables in JAVA
Ad

Similar to Classes&amp;objects (20)

PDF
Java Programming - 04 object oriented in java
PPT
Constructors
PPTX
constructors.pptx
PPT
packages and interfaces
PPT
Defining classes-and-objects-1.0
PPTX
Java-U1-C_1.2.pptx its all about the java
PPTX
3.Syntax.pptx for oops programing language
ODP
Oop scala
PPT
Classes & objects new
PPT
Sonu wiziq
PDF
Object Oriented Programming using JAVA Notes
PPTX
oopusingc.pptx
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
PPT
how to create object
PPT
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
PPT
Lecture 2
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
PPTX
UNIT - IIInew.pptx
PPT
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
PPTX
Lecture01 object oriented-programming
Java Programming - 04 object oriented in java
Constructors
constructors.pptx
packages and interfaces
Defining classes-and-objects-1.0
Java-U1-C_1.2.pptx its all about the java
3.Syntax.pptx for oops programing language
Oop scala
Classes & objects new
Sonu wiziq
Object Oriented Programming using JAVA Notes
oopusingc.pptx
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
how to create object
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Lecture 2
classandobjectunit2-150824133722-lva1-app6891.ppt
UNIT - IIInew.pptx
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Lecture01 object oriented-programming
Ad

More from M Vishnuvardhan Reddy (20)

PPTX
Python Sets_Dictionary.pptx
PPTX
Lists_tuples.pptx
PPTX
Python Control Structures.pptx
PPTX
Python Strings.pptx
PPTX
Python Basics.pptx
PPTX
Python Operators.pptx
PPTX
Python Datatypes.pptx
PPTX
DataScience.pptx
PPT
PPT
Cascading Style Sheets
PPT
Java Threads
PPT
Java Streams
PPT
Scanner class
PPT
Polymorphism
PPT
PPT
Java applets
PPT
Exception handling
PPT
Control structures
PPS
PPS
Selection sort
Python Sets_Dictionary.pptx
Lists_tuples.pptx
Python Control Structures.pptx
Python Strings.pptx
Python Basics.pptx
Python Operators.pptx
Python Datatypes.pptx
DataScience.pptx
Cascading Style Sheets
Java Threads
Java Streams
Scanner class
Polymorphism
Java applets
Exception handling
Control structures
Selection sort

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity

Classes&amp;objects

  • 1. Classes & Objects In JAVA -M Vishnuvardhan, Dept. of Computer Science, SSBN Degree College, ATP
  • 2. SSBN Degree College, ATP M Vishnuvardhan Introduction In real world we can find many objects like car, student, … All these objects have state and behavior. To represent these real world entitles Objects are used in software. Object is software representation of real life thing. In order to create an object first wee need to describe how the object should be.
  • 3. SSBN Degree College, ATP M Vishnuvardhan Class A class is a template which describes an Entity or Object. i.e., A class is a blueprint of the object. Using a class it is possible to create multiple objects A class describes an entity in two ways 1.Properties of class (gives characteristics) 2.Behavior(functionality) Eg: Student --- RollNo, Name, gender …. --- getAdmission, writeExam, getResult
  • 4. SSBN Degree College, ATP M Vishnuvardhan Representation of Class Syntax: class ClassName { declaration of properties definations of methods } class Student { int rollNo; String name; void getAdmission() { ================ } }
  • 5. SSBN Degree College, ATP M Vishnuvardhan Class - Properties These are special variables used to describe the characteristics of an Object. These are also called as attributes/ data members / data. Syntax : <<access Specifier>> dataType PropertyName; Eg: int rollNo; String name; Access Specifier controls the availability and accessibility of member of a class in different parts of the program. Eg:- public, private, protected, private protected & default. For Every member access Specifier need to specified separately
  • 6. SSBN Degree College, ATP M Vishnuvardhan Class - Methods These are functions used to describe the behavior of an Object. These are also called as member functions/ code. Syntax : <<access Specifier>> returnType methodName(<<arguments>>) { ======= // body of the method (method definition) } Eg: void getAdmisssion() { ===== } void printData(int x) { ===== }
  • 7. SSBN Degree College, ATP M Vishnuvardhan Class - Methods class Box { int length, width; double area, perimeter; void calculate() { area=length*width; perimeter=2*(length+width); } void printData() { System.out.println(“Length:”+length); System.out.println(“Width:”+width); System.out.println(“Area:”+area); System.out.println(“Perimeter:”+perimeter); } }
  • 8. SSBN Degree College, ATP M Vishnuvardhan Properties of Constructors » A constructor cannot be called like a ordinary method. » A constructor is called only once in the life time of an object. » A constructor is always invoked at the time of creation of object with the help of new keyword. » Every class must have a constructor. Without constructor object creation is not possible. » If a constructor is not defined for a class the compiler provides a constructor for the class.
  • 9. SSBN Degree College, ATP M Vishnuvardhan Constructor vs. method Java Constructor Java Method Constructor is used to initialize the state of an object. Method is used to expose behaviour of an object. Constructor must not have return type. Method must have return type. Constructor is invoked implicitly. Method is invoked explicitly. The java compiler provides a default constructor if you don't have any constructor. Method is not provided by compiler in any case. Constructor name must be same as the class name. Method name may or may not be same as class name.
  • 10. SSBN Degree College, ATP M Vishnuvardhan Types of Constructors Constructors in java can be of two types »Default Constructor: Constructor provided by the compiler is called as default constructor or a constructor with out parameters is also called as default constructor »Parameterized Constructor: Constructor with parameters is called as parameterized constructors.
  • 11. SSBN Degree College, ATP M Vishnuvardhan Types of Constructors Constructors in java can be of two types »Default Constructor: Constructor provided by the compiler is called as default constructor or a constructor with out parameters is also called as default constructor »Parameterized Constructor: Constructor with parameters is called as parameterized constructors.
  • 12. SSBN Degree College, ATP M Vishnuvardhan Questions