SlideShare a Scribd company logo
Classes and
object
Introduction
• The class is at the core of Java.
• It is the logical construct upon which the
entire Java language is built because it defines
the shape and nature of an object.
• As such, the class forms the basis for object-
oriented programming in Java.
What is a class?
• A class consists of
• a collection of fields, or variables, very much like the
named fields of a struct
• all the operations (called methods) that can be
performed on those fields
• can be instantiated
• A class describes objects and operations defined
on those objects
Defining Classes
• A class is declared by using the keyword
class. The general syntax for a class
declaration is
<modifier> class <className> { }
• Where <className> specifies the name of
the class
• class is the keyword, and
• The <modifier> specification is optional,
and specifies some characteristics of the
class.
The class hierarchy
• Classes are arranged in a hierarchy
• The root, or topmost, class is Object
• A class may have subclasses
• Each class inherits all the fields and methods of
its (possibly numerous) superclasses
Methods
• A method is a named sequence of code that
can be invoked by other Java code.
• A method takes some parameters, performs
some computations and then optionally
returns a value (or object).
• Methods can be used as part of an expression
statement.
Creating Objects
• When you write a class, you must keep in mind
the objects that will be created from it, which
correspond to the objects in the problem that
is being solved by the program. You may also
look upon the classes as data types.
• for example, of a primitive data type and assign
it a value, as follows:
int i=0;
Syntax of object
• Similarly, you can declare a variable (a reference
variable) of a class and assign it a value with the
following syntax:
<className> <variableName> = new
<classConstructor>
• Eg. Room1 obj = new Room1();
• Where <variableName> is the name of the
object and you choose this name. <className>
is the name of an existing class.
Using Object
• New operator dynamically allocates memory for
an object and returns reference to it.
Fruit plum=new Fruit();
int cals;
cals = plum.total_calories();
• Dot operator allows you to access (public)
data/methods inside Fruit class
Constructor
• Constructor initializes an object immediately on
creation.
• Constructor is automatically called immediately
after the object is created.
• Constructor name is same as class name and
have no return type not even void.
Example
Class Box
{
int w,h,d;
Box() { //contructor
w=10;
h=10;
d=10; }
public static void main(String str[])
{
Box b= new Box() }
}
ITFT-Classes and object in java

More Related Content

PPT
String classes and its methods.20
PPTX
Properties and indexers in C#
PPT
Java interfaces
PPTX
JAVA AWT
PPT
Generics in java
PPTX
Inter Thread Communicationn.pptx
PPTX
Constructor in java
PPTX
Classes,object and methods java
String classes and its methods.20
Properties and indexers in C#
Java interfaces
JAVA AWT
Generics in java
Inter Thread Communicationn.pptx
Constructor in java
Classes,object and methods java

What's hot (20)

PPS
Introduction to class in java
PDF
Java keywords
PPTX
Abstraction in java.pptx
PPTX
Arrays in java
PDF
Class and Objects in Java
PPTX
Introduction to OOP(in java) BY Govind Singh
PPTX
Access Modifier.pptx
PDF
Arrays in Java
PPTX
Method overloading
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPTX
Static Members-Java.pptx
PPTX
Java constructors
PPTX
Classes, objects in JAVA
PDF
Generics
PPTX
Java swing
PPTX
Inner classes in java
PPTX
Member Function in C++
PPT
PPTX
OOPS In JAVA.pptx
PDF
Java arrays
Introduction to class in java
Java keywords
Abstraction in java.pptx
Arrays in java
Class and Objects in Java
Introduction to OOP(in java) BY Govind Singh
Access Modifier.pptx
Arrays in Java
Method overloading
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Static Members-Java.pptx
Java constructors
Classes, objects in JAVA
Generics
Java swing
Inner classes in java
Member Function in C++
OOPS In JAVA.pptx
Java arrays
Ad

Viewers also liked (6)

PPT
classes & objects introduction
PPT
Using class and object java
PPT
Object and class
PPT
Class and object in C++
PPTX
Class and object_diagram
PPTX
Inheritance in JAVA PPT
classes & objects introduction
Using class and object java
Object and class
Class and object in C++
Class and object_diagram
Inheritance in JAVA PPT
Ad

Similar to ITFT-Classes and object in java (20)

PPT
L5 classes, objects, nested and inner class
PPTX
oop 3.pptx
PPT
Core Java unit no. 1 object and class ppt
PPT
Core Java unit no. 1 object and class ppt
PPT
Java lec class, objects and constructors
PPTX
Object Oriented Programming Tutorial.pptx
PDF
principles of proramming language in cppg
PPTX
PPTX
Object Oriented Programming - Copy.pptxb
PPTX
UNIT - IIInew.pptx
PPTX
class as the basis.pptx
PPTX
Object Oriented Programming.pptx
PPTX
Object Oriented Programming Class and Objects
PPTX
Java Classes fact general wireless-19*5.pptx
PPTX
object oriented programming-classes and objects.pptx
PPTX
IPP-M5-C1-Classes _ Objects python -S2.pptx
PPTX
Introducing classes
PPTX
BCA Class and Object (3).pptx
PPTX
Object oriented programming in java
PPT
Java Presentation.ppt
L5 classes, objects, nested and inner class
oop 3.pptx
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Java lec class, objects and constructors
Object Oriented Programming Tutorial.pptx
principles of proramming language in cppg
Object Oriented Programming - Copy.pptxb
UNIT - IIInew.pptx
class as the basis.pptx
Object Oriented Programming.pptx
Object Oriented Programming Class and Objects
Java Classes fact general wireless-19*5.pptx
object oriented programming-classes and objects.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
Introducing classes
BCA Class and Object (3).pptx
Object oriented programming in java
Java Presentation.ppt

More from Atul Sehdev (9)

PDF
itft-Overview of java language
PDF
itft-Operators in java
PDF
itft-Java evolution
PDF
itft-Inheritance in java
PDF
itft-Fundamentals of object–oriented programming in java
PDF
itft-Decision making and branching in java
PDF
ITFT-Constants, variables and data types in java
PDF
ITFT- C,c++,java and world wide web
PDF
ITFT- Applet in java
itft-Overview of java language
itft-Operators in java
itft-Java evolution
itft-Inheritance in java
itft-Fundamentals of object–oriented programming in java
itft-Decision making and branching in java
ITFT-Constants, variables and data types in java
ITFT- C,c++,java and world wide web
ITFT- Applet in java

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Pre independence Education in Inndia.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Insiders guide to clinical Medicine.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
RMMM.pdf make it easy to upload and study
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Renaissance Architecture: A Journey from Faith to Humanism
Pre independence Education in Inndia.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
O7-L3 Supply Chain Operations - ICLT Program
PPH.pptx obstetrics and gynecology in nursing
Insiders guide to clinical Medicine.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Abdominal Access Techniques with Prof. Dr. R K Mishra
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
TR - Agricultural Crops Production NC III.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

ITFT-Classes and object in java

  • 2. Introduction • The class is at the core of Java. • It is the logical construct upon which the entire Java language is built because it defines the shape and nature of an object. • As such, the class forms the basis for object- oriented programming in Java.
  • 3. What is a class? • A class consists of • a collection of fields, or variables, very much like the named fields of a struct • all the operations (called methods) that can be performed on those fields • can be instantiated • A class describes objects and operations defined on those objects
  • 4. Defining Classes • A class is declared by using the keyword class. The general syntax for a class declaration is <modifier> class <className> { } • Where <className> specifies the name of the class • class is the keyword, and • The <modifier> specification is optional, and specifies some characteristics of the class.
  • 5. The class hierarchy • Classes are arranged in a hierarchy • The root, or topmost, class is Object • A class may have subclasses • Each class inherits all the fields and methods of its (possibly numerous) superclasses
  • 6. Methods • A method is a named sequence of code that can be invoked by other Java code. • A method takes some parameters, performs some computations and then optionally returns a value (or object). • Methods can be used as part of an expression statement.
  • 7. Creating Objects • When you write a class, you must keep in mind the objects that will be created from it, which correspond to the objects in the problem that is being solved by the program. You may also look upon the classes as data types. • for example, of a primitive data type and assign it a value, as follows: int i=0;
  • 8. Syntax of object • Similarly, you can declare a variable (a reference variable) of a class and assign it a value with the following syntax: <className> <variableName> = new <classConstructor> • Eg. Room1 obj = new Room1(); • Where <variableName> is the name of the object and you choose this name. <className> is the name of an existing class.
  • 9. Using Object • New operator dynamically allocates memory for an object and returns reference to it. Fruit plum=new Fruit(); int cals; cals = plum.total_calories(); • Dot operator allows you to access (public) data/methods inside Fruit class
  • 10. Constructor • Constructor initializes an object immediately on creation. • Constructor is automatically called immediately after the object is created. • Constructor name is same as class name and have no return type not even void.
  • 11. Example Class Box { int w,h,d; Box() { //contructor w=10; h=10; d=10; } public static void main(String str[]) { Box b= new Box() } }