SlideShare a Scribd company logo
CLASSES, OBJECTS
       &
    METHODS
     Module-2
TOPICS TO COVER
   Introduction.

   Defining a class.

   Creating Objects.

   Accessing Class Members.
INTRODUCTION
   Underlying structure of each JAVA programs is
    CLASSES.
                               CREATE

            CLASS
          FIELDS
         DATA ITEMS      basic program
                                         OBJECTS
         METHODS
         FUNCTIONS       Components


               CREATE

        OBJECTS
                                METHODS
DEFINING A CLASS
   A class is a user-defined data type.
   Variables and Functions can be created within
    class
      SYNTAX                          EXAMPLE
                                  INSATNCE VARIABLES
class classname                                         class area
 {                                                        {
    field declaration;              Declaring variables     int side;
Instance variables are declared
                                                            int length;
exactly as LOCAL variables                              }

    method declaration;


}
METHOD DECLARATION
 Without methods class has NO LIFE.
 Since objects created by such class cannot respond to any

  messages.
 Thus, methods are necessary for MANIPULATING DATA.

 SYNTAX                                  EXAMPLE
                                                   class area
type method-name(parameter list)                     {
  {                                                       int side;
                                                          int length;
                                                   void get(int s, int l)
   }
                                                       {
                                                          side = s;
                                                          length = l;
   Type of the value the method returns. It can be      }
   void, int, float, double                        }
EXAMPLE FOR CREATING
               CLASSES
   Design a class Account that stores customer
    name, account number, and type of account.
    Include necessary methods to achieve
    following tasks:-
       Deposit money.
       Display balance.
       Permit withdrawal and update balance.
   An object in JAVA is essentially a block of memory that contains
    space to store all the instance variables.
   Creating an object also refers to INSTANTIATING AN OBJECT.
   Objects in JAVA are created using new. The new operator dynamically
    allocates memory for an object an returns a reference to it.
       Indicates that it does not point        class area
                                       null    Allocates at run-time
                to any object                    {
                              area a1; a1
 SYNTAX:-                                             int side;
classname objectname;
                              a1 = new area();        int length;
objectname = new classname();
                                               void get(int s, int l)
                        combined                   {
                                       a1             side = s;
                       area a1 = new area();
                                                      length = l;
                                               }
                 class area
    Values are to be assigned to variables in order to use them in
                    {
    our programs.      int side;
                       int length;
   Since we are outside the class, we cannot access the instance
                  void get(int s, int l)
                    {
    variables and methods directly.
                       side = s;
                      length = l;
    Object and dot operator are used to do this.
                  }                        area a1 = new area();
   SYNTAX:-
      objectname.variablename = value;           .
                                               a1 side = 10;

                                                      .
     objectname.methodname(parameter-list); a1 get (10, 15);
Classes, objects in JAVA
Classes, objects in JAVA
 Constructors

      Method   Overloading
 Constructor   Overloading
       Nesting   of methods
   JAVA allows objects to initialize themselves when they are
    created            CONSTRUCTOR

                                PROPERTIES:-
    • Initializes an object immediately upon creation.
    • Same name as the class in which it resides and syntactically similar
    to a method.
    • Is called automatically after the object is created.
    • Does not have return type.

                              EXAMPLE
NO RETURN TYPE




                 OUTPUT
Classes, objects in JAVA
   Methods have same name, but different parameter list .
   Is used when objects are required to perform similar tasks but
    using different input parameters.
   Also known as POLYMORPHISM.
   Here, the aim is to provide several method definitions all with
    same name, but different parameter lists.
   The difference may either in number or type of arguments

      Method’s return type does not play
      any role in this
   In addition to overloading methods, you can also
    overload constructor method

                       EXAMPLE
   A method of a class can be called only by an
    object of that class using dot operator.




    A method can be called by using only its name by
          another method of the same class

                      NESTING OF
                       METHODS
STATIC MEMBERS

 Is used to define a member that is common to all objects and accessed

  without using a particular object.

 Thus member belongs to the class as a whole rather than the objects

  created from the class.

 Used when we want to have a variable common to all instances of a

  class.

SYNTAX:-
static int count;         STATIC MEMBERS
                                     Referred to as
static int max(int x, int
y)                Class variables and Class methods
EXAMPLE
RESTRICTIONS FACED BY STATIC
                METHODS:-


            STATIC
         METHODS ARE
         CALLED USING
         CLASS NAME




 They can only call other static methods.

 They can only access static data.

 They cannot refer to this or super in any way.
USING OBJECTS as PARAMETERS

 We know how to pass simple types as parameters to
  methods.
 It is possible, correct and common to pass OBJECTS
  to methods.




             EXAMPLE
CALL by VALUE vs. CALL by REFERENCE

CALL BY VALUE                  CALL BY REFERANCE

This method copies the value   In this method, reference to
of an argument into the        an argument is passed to the
formal parameter of the        parameter.
subroutine
Does not access actual         This reference is used to
argument                       access the actual argument.
Thus, changes made to          Thus, changes made to
parameter of the subroutine    parameter will have an effect
have no effect on the          on the argument.
argument.
EXAMPLE



                 REMEMBE
                    R
CALL by VALUE:- Simple
type arguments are passed
       to methods.

CALL by REFERENCE:-
Objects are passed to
methods
RECURSION

 JAVA supports recursion.

 Recursion is the process of defining something in

 terms of itself.

 A method that calls itself is said to be recursive.
VISIBILITY CONTROL

 Visibility modifiers areused to restrict the access to
  certain variables and methods from outside the class.
 Also known as ACCESS MODIFIERS.

                         Visibility
                          Labels



           PUBLIC                         PROTECTED
                          PRIVATE
VISIBILITY CONTROL (Contd..)

PUBLIC                     Visible to entire class in which it is defined and
                           All the class Outside


PRIVATE                    Enjoys highest degree of protection.
                           Accessible only with their own class.
                           Cannot be inherited, thus not accessible in sub-class.

Friendly                   When no access modifier is specified then the default
                           version of public accessibility is known as
                           “FRIENDLY”

PUBLIC
PROTECTED                    ItsFriendly between PUBLIC ACCESS & FRIENDLY
                                 level lies
                             ACCESS.
Makes fields visible in all Makes the fields visibleonly only to all classes and
                                Makes fields visible not in
classes, regardless of their subclasses in same package but also to subclasses in
                                the same package.
packages                     other packages
Classes, objects in JAVA

More Related Content

What's hot (20)

Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Methods in java
Methods in javaMethods in java
Methods in java
chauhankapil
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
HrithikShinde
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
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
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
Niloy Saha
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
Somya Bagai
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 

Similar to Classes, objects in JAVA (20)

Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Reflection
ReflectionReflection
Reflection
Piyush Mittal
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
Suresh Mohta
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
bharath yelugula
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
C# interview
C# interviewC# interview
C# interview
Thomson Reuters
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
Lecture 8 Library classes
Lecture 8 Library classesLecture 8 Library classes
Lecture 8 Library classes
Syed Afaq Shah MACS CP
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
shubhra chauhan
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
Unit i
Unit iUnit i
Unit i
snehaarao19
 
oops-1
oops-1oops-1
oops-1
snehaarao19
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
Lakshmi Sarvani Videla
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
Suresh Mohta
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
bharath yelugula
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Ad

More from Abhilash Nair (20)

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
Abhilash Nair
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
Abhilash Nair
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
Abhilash Nair
 
MSI Shift Registers
MSI Shift RegistersMSI Shift Registers
MSI Shift Registers
Abhilash Nair
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
Abhilash Nair
 
VHDL - Part 2
VHDL - Part 2VHDL - Part 2
VHDL - Part 2
Abhilash Nair
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
Abhilash Nair
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
Abhilash Nair
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
Abhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
Abhilash Nair
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
Abhilash Nair
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
Abhilash Nair
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
Abhilash Nair
 
FPGA
FPGAFPGA
FPGA
Abhilash Nair
 
FPLDs
FPLDsFPLDs
FPLDs
Abhilash Nair
 
CPLDs
CPLDsCPLDs
CPLDs
Abhilash Nair
 
CPLD & FPLD
CPLD & FPLDCPLD & FPLD
CPLD & FPLD
Abhilash Nair
 
CPLDs
CPLDsCPLDs
CPLDs
Abhilash Nair
 
Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
Abhilash Nair
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
Abhilash Nair
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
Abhilash Nair
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
Abhilash Nair
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
Abhilash Nair
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
Abhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
Abhilash Nair
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
Abhilash Nair
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
Abhilash Nair
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
Abhilash Nair
 
Ad

Recently uploaded (20)

Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 

Classes, objects in JAVA

  • 1. CLASSES, OBJECTS & METHODS Module-2
  • 2. TOPICS TO COVER  Introduction.  Defining a class.  Creating Objects.  Accessing Class Members.
  • 3. INTRODUCTION  Underlying structure of each JAVA programs is CLASSES. CREATE CLASS FIELDS DATA ITEMS basic program OBJECTS METHODS FUNCTIONS Components CREATE OBJECTS METHODS
  • 4. DEFINING A CLASS  A class is a user-defined data type.  Variables and Functions can be created within class SYNTAX EXAMPLE INSATNCE VARIABLES class classname class area { { field declaration; Declaring variables int side; Instance variables are declared int length; exactly as LOCAL variables } method declaration; }
  • 5. METHOD DECLARATION  Without methods class has NO LIFE.  Since objects created by such class cannot respond to any messages.  Thus, methods are necessary for MANIPULATING DATA. SYNTAX EXAMPLE class area type method-name(parameter list) { { int side; int length; void get(int s, int l) } { side = s; length = l; Type of the value the method returns. It can be } void, int, float, double }
  • 6. EXAMPLE FOR CREATING CLASSES  Design a class Account that stores customer name, account number, and type of account. Include necessary methods to achieve following tasks:-  Deposit money.  Display balance.  Permit withdrawal and update balance.
  • 7. An object in JAVA is essentially a block of memory that contains space to store all the instance variables.  Creating an object also refers to INSTANTIATING AN OBJECT.  Objects in JAVA are created using new. The new operator dynamically allocates memory for an object an returns a reference to it. Indicates that it does not point class area null Allocates at run-time to any object { area a1; a1 SYNTAX:- int side; classname objectname; a1 = new area(); int length; objectname = new classname(); void get(int s, int l) combined { a1 side = s; area a1 = new area(); length = l; }
  • 8. class area Values are to be assigned to variables in order to use them in { our programs. int side; int length;  Since we are outside the class, we cannot access the instance void get(int s, int l) { variables and methods directly. side = s;  length = l; Object and dot operator are used to do this. } area a1 = new area();  SYNTAX:- objectname.variablename = value; . a1 side = 10; . objectname.methodname(parameter-list); a1 get (10, 15);
  • 11.  Constructors  Method Overloading  Constructor Overloading  Nesting of methods
  • 12. JAVA allows objects to initialize themselves when they are created CONSTRUCTOR PROPERTIES:- • Initializes an object immediately upon creation. • Same name as the class in which it resides and syntactically similar to a method. • Is called automatically after the object is created. • Does not have return type. EXAMPLE
  • 13. NO RETURN TYPE OUTPUT
  • 15. Methods have same name, but different parameter list .  Is used when objects are required to perform similar tasks but using different input parameters.  Also known as POLYMORPHISM.  Here, the aim is to provide several method definitions all with same name, but different parameter lists.  The difference may either in number or type of arguments Method’s return type does not play any role in this
  • 16. In addition to overloading methods, you can also overload constructor method EXAMPLE
  • 17. A method of a class can be called only by an object of that class using dot operator. A method can be called by using only its name by another method of the same class NESTING OF METHODS
  • 18. STATIC MEMBERS  Is used to define a member that is common to all objects and accessed without using a particular object.  Thus member belongs to the class as a whole rather than the objects created from the class.  Used when we want to have a variable common to all instances of a class. SYNTAX:- static int count; STATIC MEMBERS Referred to as static int max(int x, int y) Class variables and Class methods
  • 20. RESTRICTIONS FACED BY STATIC METHODS:- STATIC METHODS ARE CALLED USING CLASS NAME  They can only call other static methods.  They can only access static data.  They cannot refer to this or super in any way.
  • 21. USING OBJECTS as PARAMETERS  We know how to pass simple types as parameters to methods.  It is possible, correct and common to pass OBJECTS to methods. EXAMPLE
  • 22. CALL by VALUE vs. CALL by REFERENCE CALL BY VALUE CALL BY REFERANCE This method copies the value In this method, reference to of an argument into the an argument is passed to the formal parameter of the parameter. subroutine Does not access actual This reference is used to argument access the actual argument. Thus, changes made to Thus, changes made to parameter of the subroutine parameter will have an effect have no effect on the on the argument. argument.
  • 23. EXAMPLE REMEMBE R CALL by VALUE:- Simple type arguments are passed to methods. CALL by REFERENCE:- Objects are passed to methods
  • 24. RECURSION  JAVA supports recursion.  Recursion is the process of defining something in terms of itself.  A method that calls itself is said to be recursive.
  • 25. VISIBILITY CONTROL  Visibility modifiers areused to restrict the access to certain variables and methods from outside the class.  Also known as ACCESS MODIFIERS. Visibility Labels PUBLIC PROTECTED PRIVATE
  • 26. VISIBILITY CONTROL (Contd..) PUBLIC Visible to entire class in which it is defined and All the class Outside PRIVATE Enjoys highest degree of protection. Accessible only with their own class. Cannot be inherited, thus not accessible in sub-class. Friendly When no access modifier is specified then the default version of public accessibility is known as “FRIENDLY” PUBLIC PROTECTED ItsFriendly between PUBLIC ACCESS & FRIENDLY level lies ACCESS. Makes fields visible in all Makes the fields visibleonly only to all classes and Makes fields visible not in classes, regardless of their subclasses in same package but also to subclasses in the same package. packages other packages