SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Programming in JAVA
by
P.Vishnu Priya(181613)
P.A.Abinaya(181601)
II B.Sc Mathematics(CA)
SBK College,Aruppukottai
TO
K.Padma Priya M.Sc(CS),M.Phill.
Assistant professor
Dept of mathematics(CA)
SBK College,Aruppukottai
classes,objects&methods.
synposis
 Constructors
 Method overloading
 Static member function
 Nesting of methods
 Overriding methods
Constructors:
 Constructors have the same name as the class itself.
 Java supports a special type of method called a
constructor.
 They don’t specify a return type not even void.
rect1.getdata(15,10);
class Rectangle
{
int length;
int width;
Rectangle(int x,int y) //constructor method
{
length=x;
width=y;
}
int rectArea()
{
return(length*width);
}
}
Methodsoverloading:
 Method overloading have the same name but different
parameter lists and different definitions.
 Method overloading is used when objects are required
to perform similar tasks but using different input
parameters.
 In each parameter lists should be unique.
class Room
{
float length;
float breadth;
Room(float x,float y) //constructor 1
{
length=x;
breadth=y;
}
Room (float x) //constructor 2
{
length = breadth = x;
}
int area()
{
return(length*breadth);
}
}
Here we are overloading the constructor method
Room(). An object representing a rectangular room will
be created as
Room room1=new Room(25.0,15.0);
//using constructor 1
We may create the corresponding object as
Room room2=new Room(20.0);
//using constructor 2
Staticmembers:
 Static member contains two section. One can declares
variables and the other declares methods.
 These variables and methods are called instance
variable and instance methods.
 They are access using the objects.[with dot operator].
static int count;
static int max(int x,int y);
 Static member can be use math function.
float x = Math.sqrt(25.0);
 The method sqrt is a class method defined in Math
class.
 Static methods are called using class names.
 No object have been created for use.
Static methods have several restrictions:
 They can only call other static methods.
 They can only access static data.
 They cannot refer to this or super in any way.
Nestingof methods:
 A method can be called by using only its name by
another method of same class.
 This is know as nesting of methods.
 The class Nesting defines one constructor and two
methods namely largest() and display().
 The methods display() calls the method largest
() to determine the largest of the two numbers and
then displays the result.
OverridingMethods:
 we have seen that the method define in a
super class is inherited by its subclass and is
used by the objects created by the subclass.
 Method inheritance enables us to define
and use methods repeatedly in subclass
without having to define the methods again
in subclass.
 This method display() is overriden.
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
Navtar Sidhu Brar
 

Was ist angesagt? (20)

Datastructure
DatastructureDatastructure
Datastructure
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Ii pu cs practical viva voce questions
Ii pu cs  practical viva voce questionsIi pu cs  practical viva voce questions
Ii pu cs practical viva voce questions
 
R data types
R data typesR data types
R data types
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
2 introduction to data structure
2  introduction to data structure2  introduction to data structure
2 introduction to data structure
 
Data Structures Notes 2021
Data Structures Notes 2021Data Structures Notes 2021
Data Structures Notes 2021
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
Dev Concepts: Object-Oriented Programming
Dev Concepts: Object-Oriented ProgrammingDev Concepts: Object-Oriented Programming
Dev Concepts: Object-Oriented Programming
 
how to create object
how to create objecthow to create object
how to create object
 
Data structures
Data structuresData structures
Data structures
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
Data structure power point presentation
Data structure power point presentation Data structure power point presentation
Data structure power point presentation
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Data structure using c++
Data structure using c++Data structure using c++
Data structure using c++
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard Library
 

Ähnlich wie Classes,object and methods jav

9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
Terry Yoast
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
sotlsoc
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
Palak Sanghani
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
PRN USM
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
trixiacruz
 

Ähnlich wie Classes,object and methods jav (20)

Object and class
Object and classObject and class
Object and class
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
Hemajava
HemajavaHemajava
Hemajava
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Java class
Java classJava class
Java class
 
Chap08
Chap08Chap08
Chap08
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
 
C# p8
C# p8C# p8
C# p8
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptx
 

Mehr von Padma Kannan (13)

B tree
B treeB tree
B tree
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Java packags
Java packagsJava packags
Java packags
 
Java and c++
Java and c++Java and c++
Java and c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in c++,
Functions in c++,Functions in c++,
Functions in c++,
 
Functions of dbms
Functions  of dbmsFunctions  of dbms
Functions of dbms
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
 
LEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITYLEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITY
 
Social networking risks
Social networking risksSocial networking risks
Social networking risks
 
Inheritance
InheritanceInheritance
Inheritance
 
Excel2002
Excel2002Excel2002
Excel2002
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Classes,object and methods jav

  • 1. Programming in JAVA by P.Vishnu Priya(181613) P.A.Abinaya(181601) II B.Sc Mathematics(CA) SBK College,Aruppukottai TO K.Padma Priya M.Sc(CS),M.Phill. Assistant professor Dept of mathematics(CA) SBK College,Aruppukottai
  • 2. classes,objects&methods. synposis  Constructors  Method overloading  Static member function  Nesting of methods  Overriding methods
  • 3. Constructors:  Constructors have the same name as the class itself.  Java supports a special type of method called a constructor.  They don’t specify a return type not even void. rect1.getdata(15,10);
  • 4. class Rectangle { int length; int width; Rectangle(int x,int y) //constructor method { length=x; width=y; } int rectArea() { return(length*width); } }
  • 5. Methodsoverloading:  Method overloading have the same name but different parameter lists and different definitions.  Method overloading is used when objects are required to perform similar tasks but using different input parameters.  In each parameter lists should be unique.
  • 6. class Room { float length; float breadth; Room(float x,float y) //constructor 1 { length=x; breadth=y; } Room (float x) //constructor 2 { length = breadth = x; } int area() { return(length*breadth); } }
  • 7. Here we are overloading the constructor method Room(). An object representing a rectangular room will be created as Room room1=new Room(25.0,15.0); //using constructor 1 We may create the corresponding object as Room room2=new Room(20.0); //using constructor 2
  • 8. Staticmembers:  Static member contains two section. One can declares variables and the other declares methods.  These variables and methods are called instance variable and instance methods.  They are access using the objects.[with dot operator]. static int count; static int max(int x,int y);  Static member can be use math function.
  • 9. float x = Math.sqrt(25.0);  The method sqrt is a class method defined in Math class.  Static methods are called using class names.  No object have been created for use. Static methods have several restrictions:  They can only call other static methods.  They can only access static data.  They cannot refer to this or super in any way.
  • 10. Nestingof methods:  A method can be called by using only its name by another method of same class.  This is know as nesting of methods.  The class Nesting defines one constructor and two methods namely largest() and display().  The methods display() calls the method largest () to determine the largest of the two numbers and then displays the result.
  • 11. OverridingMethods:  we have seen that the method define in a super class is inherited by its subclass and is used by the objects created by the subclass.  Method inheritance enables us to define and use methods repeatedly in subclass without having to define the methods again in subclass.  This method display() is overriden.