SlideShare a Scribd company logo
Pundra University of Science & Technology
Department of Computer Science & Engineering
Name: Md. Sihab Uddin
Batch No: 6th
Semester No: 4th
Roll No: 05
Outline
• Program Structure
• Concept of Class
• Concept of Object
• Concept of Constructor
• Method
Program Structure
• Structure
Import Statement
Package Statement
Class Definition
Inheritance Statement
Interface Statement
Main Method
Concept of Class
• A class is simply a representation of a type of object
• It is the blueprint/ plan/ template that describe the
details of an object
• For example- mango, apple, orange are the members of
the class fruits
• If fruits has been defined as a class, then the statement
Fruits mango;
• It will create an object mango belonging to the class
fruit
Cont……..
• Java is a case-sensitive language
• Class declaration
• Opening braces
• The main line
• The output line
Class Csepu
{
Public static void main (String args[])
{
System.out.println(“Java is better than C++”);
}
}
Cont……………
• Class declaration
Class Csepu
– This line uses the keyword class to declare that a new class is
being defined
– Csepu is the name of the class
• Opening braces
{
……
}
– The class definition begins with the opening curly brace ({) and
ends with the closing curly brace (}).
– The elements between the two braces are members of the class
Cont………..
• The main line
Public static void main (String args[])
– The keyword public means that the method main() can
be accessed by any other Java class.
– The keyword static means that you don’t have to create
an instance of this class to use this method.
– The keyword void means that the method main()
doesn’t return any value to the calling program.
– The keyword String[] args tells us that this method
will receive an array of characters as the argument
Cont…….
• The Output line
System.out.println(“Java is better than C++”);
– This is similar to the printf() statement of C
– Since Java is a true object oriented language, every method
must be part of an object
– The println method is a member of the out object, which is
a static data member of System class
– The method println always appends a newline character to
the end of the string
– This means that any subsequent output will start on a new
line
Object
• Objects are instances of a class. It is the building block
of OOP.
• They are the basic runtime entities in an object
oriented system
• They may present a person, a place, a bank account, a
table of data or any item that the program may handle
• Object must have the following three characteristics:
– Identity
– State
– Behavior
Concept of Constructors
• A constructor initializes an object when it is created
• It has the same name as its class and is syntactically similar to a method
• However, constructors have no explicit return type
• simple example class Adition
{ public void add()
{int a,b,add;
a=4;b=5;
add=a+b;
System.out.println("Result of Add:
"+add);
}
}
public class Exmcons1
{ public static void main (String args[])
{
Adition obj = new Adition();
obj.add();
}
}
Concept of Methods
• Methods are the interface or communications between
program components
• A Java method is a collection of statements that are grouped
together to perform an operation
• As an example when we call the System.out.println method…
– The system actually executes several statements in order to
display a message on the console
– In general, a method has the following syntax
Modifier returnValueType methodName (list of parameters)
{
//method of body;
}
Cont…………..
Declaring a Methods
• Modifiers
– The modifier, which is optional, tells the compiler how
to call the method
– This defines the access type of the method
• Return Type
– A method may return a value
– The returnValueType is the data type of the value the
method returns
– Some methods perform the desired operations without
returning a value
– In this case, the returnValueType is the keyword void
Cont………….
• Method Name
– This is the actual name of the method
– The method name and the parameter list together constitute
the method signature
• Parameters
– A parameter is like a place holder
– When a method is invoked, pass a value to the parameter
– This value is referred to as actual parameter or argument
– The parameter list refers to the type, order, and number of
the parameters of a method
– Parameters are optional; that is, a method may contain no
parameters
Cont………….
• Method Body
– The method body contains a collection of statements that define
what the method does
• Example
– The following defined method called max()
– This method takes two parameters num1 and num2 and returns
the maximum between the two
public static int max(int num1, int num2)
{
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}

More Related Content

What's hot

Abstract class
Abstract classAbstract class
Abstract class
Tony Nguyen
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
kamal kotecha
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
OOP java
OOP javaOOP java
OOP java
xball977
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
teach4uin
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
Raghuveer Guthikonda
 
Java program structure
Java program structureJava program structure
Java program structure
shalinikarunakaran1
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
Lovely Professional University
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
atozknowledge .com
 

What's hot (20)

Abstract class
Abstract classAbstract class
Abstract class
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java package
Java packageJava package
Java package
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Interface in java
Interface in javaInterface in java
Interface in java
 
OOP java
OOP javaOOP java
OOP java
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Java program structure
Java program structureJava program structure
Java program structure
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 

Similar to Java class,object,method introduction

Lec4
Lec4Lec4
02basics
02basics02basics
02basics
Waheed Warraich
 
Java method
Java methodJava method
Java method
sunilchute1
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
SamuelAnsong6
 
Data structure
Data structureData structure
Data structure
Muhammad Farhan
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
Explain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).pptExplain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).ppt
ayaankim007
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
 
11. java methods
11. java methods11. java methods
11. java methods
M H Buddhika Ariyaratne
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
Yonas D. Ebren
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
valerie5142000
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
ansariparveen06
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
AqeelAbbas94
 
array Details
array Detailsarray Details
array Details
shivas379526
 

Similar to Java class,object,method introduction (20)

Lec4
Lec4Lec4
Lec4
 
02basics
02basics02basics
02basics
 
Java method
Java methodJava method
Java method
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Data structure
Data structureData structure
Data structure
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Explain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).pptExplain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).ppt
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
11. java methods
11. java methods11. java methods
11. java methods
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
array Details
array Detailsarray Details
array Details
 

Recently uploaded

IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 

Recently uploaded (20)

IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 

Java class,object,method introduction

  • 1. Pundra University of Science & Technology Department of Computer Science & Engineering Name: Md. Sihab Uddin Batch No: 6th Semester No: 4th Roll No: 05
  • 2. Outline • Program Structure • Concept of Class • Concept of Object • Concept of Constructor • Method
  • 3. Program Structure • Structure Import Statement Package Statement Class Definition Inheritance Statement Interface Statement Main Method
  • 4. Concept of Class • A class is simply a representation of a type of object • It is the blueprint/ plan/ template that describe the details of an object • For example- mango, apple, orange are the members of the class fruits • If fruits has been defined as a class, then the statement Fruits mango; • It will create an object mango belonging to the class fruit
  • 5. Cont…….. • Java is a case-sensitive language • Class declaration • Opening braces • The main line • The output line Class Csepu { Public static void main (String args[]) { System.out.println(“Java is better than C++”); } }
  • 6. Cont…………… • Class declaration Class Csepu – This line uses the keyword class to declare that a new class is being defined – Csepu is the name of the class • Opening braces { …… } – The class definition begins with the opening curly brace ({) and ends with the closing curly brace (}). – The elements between the two braces are members of the class
  • 7. Cont……….. • The main line Public static void main (String args[]) – The keyword public means that the method main() can be accessed by any other Java class. – The keyword static means that you don’t have to create an instance of this class to use this method. – The keyword void means that the method main() doesn’t return any value to the calling program. – The keyword String[] args tells us that this method will receive an array of characters as the argument
  • 8. Cont……. • The Output line System.out.println(“Java is better than C++”); – This is similar to the printf() statement of C – Since Java is a true object oriented language, every method must be part of an object – The println method is a member of the out object, which is a static data member of System class – The method println always appends a newline character to the end of the string – This means that any subsequent output will start on a new line
  • 9. Object • Objects are instances of a class. It is the building block of OOP. • They are the basic runtime entities in an object oriented system • They may present a person, a place, a bank account, a table of data or any item that the program may handle • Object must have the following three characteristics: – Identity – State – Behavior
  • 10. Concept of Constructors • A constructor initializes an object when it is created • It has the same name as its class and is syntactically similar to a method • However, constructors have no explicit return type • simple example class Adition { public void add() {int a,b,add; a=4;b=5; add=a+b; System.out.println("Result of Add: "+add); } } public class Exmcons1 { public static void main (String args[]) { Adition obj = new Adition(); obj.add(); } }
  • 11. Concept of Methods • Methods are the interface or communications between program components • A Java method is a collection of statements that are grouped together to perform an operation • As an example when we call the System.out.println method… – The system actually executes several statements in order to display a message on the console – In general, a method has the following syntax Modifier returnValueType methodName (list of parameters) { //method of body; }
  • 13. Declaring a Methods • Modifiers – The modifier, which is optional, tells the compiler how to call the method – This defines the access type of the method • Return Type – A method may return a value – The returnValueType is the data type of the value the method returns – Some methods perform the desired operations without returning a value – In this case, the returnValueType is the keyword void
  • 14. Cont…………. • Method Name – This is the actual name of the method – The method name and the parameter list together constitute the method signature • Parameters – A parameter is like a place holder – When a method is invoked, pass a value to the parameter – This value is referred to as actual parameter or argument – The parameter list refers to the type, order, and number of the parameters of a method – Parameters are optional; that is, a method may contain no parameters
  • 15. Cont…………. • Method Body – The method body contains a collection of statements that define what the method does • Example – The following defined method called max() – This method takes two parameters num1 and num2 and returns the maximum between the two public static int max(int num1, int num2) { int result; if (num1 > num2) result = num1; else result = num2; return result; }