SlideShare a Scribd company logo
1 of 81
Great Introduction to OOP




         Prepared by : Tom Hunter
  Edited and Updated By:Mohamed Shahpoup

                                     Java I—Copyright © 2000 Tom Hunter
1- Introduction.
2- What is OOP.
3- OOP Vocabulary .
4- Creating Our First Class Object.
5- Using this Keyword.


                             Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects
• How did companies like Dell, Compaq and
Gateway get so big?


• They bought components from other companies
and assembled the pieces into their products.




                                   Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • Dell didn’t design its own
       motherboards.
 • Compaq didn’t engineer its own
 hard drives or operating systems.




 • They bought the pieces and let somebody else do
 the engineering.

                                      Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • Dell, Compaq and Gateway let somebody else
 reinvent the power supply or the motherboard.


 • Object-Oriented programming is the same idea.


 • A program is composed of generic objects, with
 certain standard properties, and certain standard
 operations the objects can perform.

                                       Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

• Dell doesn’t care how the power supply works.


• Dell cares if the power supply works.


• How the power supply works is hidden and private.


• Only the end result is visible.

                                          Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

• Dell is only exposed to the end result.


• Most important is the power supply’s public face—
the power.


• Dell doesn’t care how it works internally.




                                            Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects


 • Likewise, in OOP, you only care about what the
 objects expose.


 • You can’t know how somebody else’s object
 works.




                                      Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • You don’t care how the JOptionPane works.
 • You care about its public methods—its “interface”.



     You only care about its
         public methods !

                                       Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • In traditional procedural programming, you
 search for verbs in the problem definition.


 • In procedural programming, the verbs directly
 suggest procedures and then, lastly, you think of
 data variables to go with those procedures.




                                        Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

      • In OOP, you put data structures first,
      and then look at the algorithms that
      operate on the data.




                                         Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • The secret to effective OOP:
 Each object carries out a small set of related tasks.
        If an object needs a task done—but that task
 isn’t the job of that object—then that object asks
 another object to do the task.

           “If I can’t do it, then I’ll
           ask somebody who can.”

                                         Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • Again, since the first object can’t do the
 task, it asks the second object to carry out the
 task.
 • In OOP jargon, we say:


      “A Client object sends a
     message to a Server object.”

                                     Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • In OOP, one object must never directly
 manipulate the internal data of another object.
              encapsulation
 • Rather, all communication is through
 “messages”.


 (A message is another name for a method call.)


                                          Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • When you design your object to hide how it
 handles requests...
            (messages / method calls)
                      ...you make it easily reusable.




                                        Java I—Copyright © 2000 Tom Hunter
The Genius of Using Objects

 • When you see a Windows OS computer lock up,
 and you do a CTRL-ALT-DEL, the “Close
 Program” window that pops up might say:

                 (Not Responding)
 • That message means that some Windows object
 is not responding to messages.
 • Some program called a method, but Windows
 failed to respond. (No surprise)

                                    Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary


    Class




             Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
class
• The term class is the blueprint which the object is
actually made, or “instantiated.”
                MyClass boop;
          boop = new MyClass();
We are now familiar with this: The first
“MyClass boop; ” makes a reference called
“boop.”
                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary

   MyClass boop;
         At this point, the reference called
   “boop” does not actually point to any
   existing object.
       Soon, it will point to an object of type
   MyClass, but now the object doesn’t exist.




                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary

   MyClass boop = new MyClass();
       When this statement executes, the new
  keyword executes the default Constructor
  for MyClass, which actually creates an object in
  memory and assigns that reference to boop.
       The handle to that just-created object is
  given to the MyClass reference boop.
  Now boop points to the new MyClass object.

                                        Java I—Copyright © 2000 Tom Hunter
state
   behavior
        identity

                   Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state
       behavior
             identity
 • Each object in OOP has three key characteristics:
 What?
       How?
             Who?


                                           Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state      behavior        identity


 • Key characteristics:
      (What) What is the object’s state?
      (How) What is the object’s behavior?
      (Who) What is the object’s identity?



                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state        behavior       identity


 • All instances of a class have the same instance
 variables, but of course those variables have
 different values inside them.
 • The state—or current values—for an instance of a
 class, is called the “state” of that class.
 • The current values of those variables define the
 current situation or state of this instance of the
 class.
                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state      behavior     identity
 • For example, if I have a class called
 HourlyEmployee, then it contains instance
 variables:
      first_name
      last_name
      soc_sec_number
      hourly_rate
      current_vacation_time
                                    Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state        behavior        identity


 • All objects that are instances of the same class
 share the same behavior.
 • They all have the same methods.




                                         Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state         behavior        identity
 • My class is:    HourlyEmployee
 • All instances of this class have these methods:
 calculate_pay()
       setName()
                                    Methods
       getName()
             setSSN()
             getSSN()
                   getVacationTime()
                   setVacationTime()
                         getHourlyRate()
                         setHourlyRate()
                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 state         behavior identity
 • My class is:   HourlyEmployee

 • Every example, or instantiation, of this class
 has the same methods (behavior) available to it.




                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state       behavior       identity
      • My class is: HourlyEmployee

• Let’s instantiate HourlyEmployee :

HourlyEmployee joseph; // empty reference.

joseph = new HourlyEmployee(‘Joe’,’Smith’,

           ’598-22-7893’,’$10.00’,’22.25’);

• Now, I have created an instance of the class
HourlyEmployee.
                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state        behavior             identity
• My class is:   HourlyEmployee

• I have instantiated HourlyEmployee.

• My instance is called joseph.

• The identity of my instance is joseph.



                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state     behavior          identity
• The identity of my instance is
     joseph.
• The state of my instance is:
     first_name = ‘Joe’
     last_name = ’Smith’
     soc_sec_number = ’598-22-7893’
     hourly_rate = ’$10.00’
     current_vacation_time = ’22.25’
• The behavior of my instance is:
     calculate_pay()
     setName()
     getName()
     setSSN()
     getSSN()
                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary identity for each of the three.
       Tell me the
state        behavior         identity
• Now, I will instantiate three objects:
HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);

HourlyEmployee theodore;
theodore = new HourlyEmployee(‘Ted’,’L.’,
               ’681-22-9875’,’$10.00’,’22’);

HourlyEmployee david;
david = new HourlyEmployee(‘Dave’,’D.’,
               ’198-99-0098’,’$15.00’,’8’);


                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state     behavior        identity
• Identity is the reference to this instantiation.
HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);

HourlyEmployee theodore;
theodore = new HourlyEmployee(‘Ted’,’L.’,
               ’681-22-9875’,’$10.00’,’22’);

HourlyEmployee david;
david = new HourlyEmployee(‘Dave’,’D.’,
               ’198-99-0098’,’$15.00’,’8’);


                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary behaviors for each of the three.
      Tell me the
state       behavior   identity


HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);

HourlyEmployee theodore;
theodore = new HourlyEmployee(‘Ted’,’L.’,
               ’681-22-9875’,’$10.00’,’22’);

HourlyEmployee david;
david = new HourlyEmployee(‘Dave’,’D.’,
               ’198-99-0098’,’$15.00’,’8’);


                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state         behavior       identity
• All three have the exact same behaviors.
HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);

HourlyEmployee theodore;
theodore = new HourlyEmployee(‘Ted’,’L.’,
               ’681-22-9875’,’$10.00’,’22’);

HourlyEmployee david;
david = new HourlyEmployee(‘Dave’,’D.’,
               ’198-99-0098’,’$15.00’,’8’);


                                     Java I—Copyright © 2000 Tom Hunter
OOP Vocabularythe state for each of the three.
       Tell me
state      behavior      identity


HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);

HourlyEmployee theodore;
theodore = new HourlyEmployee(‘Ted’,’L.’,
               ’681-22-9875’,’$10.00’,’22’);

HourlyEmployee david;
david = new HourlyEmployee(‘Dave’,’D.’,
               ’198-99-0098’,’$15.00’,’8’);


                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state        behavior     identity
• The state of each instance is defined by its
instance variables.
HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);

HourlyEmployee theodore;
theodore = new HourlyEmployee(‘Ted’,’L.’,
               ’681-22-9875’,’$10.00’,’22’);

HourlyEmployee david;
david = new HourlyEmployee(‘Dave’,’D.’,
               ’198-99-0098’,’$15.00’,’8’);

                                       Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
state       behavior       identity
• The state of an instance can only be changed by
going through its methods or behaviors.
HourlyEmployee marie;
marie = new HourlyEmployee(‘Mary’,’J.’,
               ’555-24-1516’,’$30.00’,’0’);


     marie.setSSN( ‘444-33-1264’ );




                                     Java I—Copyright © 2000 Tom Hunter
Class Scope



              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
       Class Scope
 • A class’s Instance variables and methods have a
 thing called “class scope.”

 • Within the class (within the scope of that class), class
 member variables are accessible by name. (static Members)
 • So, inside or outside of any method in that class, those
 instance variables can be reached from anywhere in the
 class.




                                               Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
     Class Scope

 • If a member variable has been (foolishly) declared
 public, then it can be accessed outside of the class by
 simply referencing as follows:

         ClassName.primitive_variable

         ClassName.Object_variable.

 • Another instance of this class has access to the
 instance variables in any other instance of this class.
 • You can use the instance identifier or the class name if
 it is declared as a “static” variable.        Java I—Copyright © 2000 Tom Hunter
Cosmic Base Class



              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Cosmic Base Class
 • In Java, all classes are built on other classes.
 • We say, that one class extends another class.
 • Ultimately, all classes in Java stem from one
 central “Cosmic Base Class” called Object.
 • Even if you didn’t use the word “extends” in your
 class definition, you were still always extending
 Object by default.

                                          Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Base Class
 • When you extend any “Base Class”, the new
 (derived) class has all the properties ( instance
 variables) and methods of its parent, or Base Class.


 • You can choose to modify or keep any method of
 the parent, or you can create methods that only
 apply to the child or “inherited” class.


                                        Java I—Copyright © 2000 Tom Hunter
Inheritance




              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Inheritance
 • The concept of extending a base class is called
 “Inheritance.”
 • Inheritance is the second fundamental concept of
 Object-Oriented programming.
      (Encapsulation is the first,
      Polymorphism is the third)



                                        Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes
 • Classes can be related to each other in one of three
 alternative ways:

       use
       containment ( “has-a” )
       inheritance ( “is-a” )



                                              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary

 • When one class sends messages to another class, we say
 it “uses” the class that receives its messages.

       Use




                                           Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary

 • When one class lives as an Instance Variable within
 another class, we say it is “Contained”, a “has-a”
 relationship.

       Containment ( “has-a” )




                                            Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary

 • When one class inherits from another class, we say it is
 an “is-a” relationship.

       inheritance ( “is-a” )




                                              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: use

 • Imagine that we have a class Order.


 • Class Order needs to use the class Account, in order
 to check for credit status.




                                          Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: use

 • Generally, if a method of class Order
 sends a message to an object of class Account,
  then Order uses Account.

                                       Account
          Order           message

 • In other words, Order uses Account when
 Order calls methods of Account.


                                          Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: use

 • Also, we say class Order uses class Account if:

 • A method of Order :
             creates
             receives or
             returns
             objects of class Account .




                                          Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: use

 • Design Tip:
      Avoid the “use” relationship whenever
 you can. If you “use” somebody else’s class,
 then any changes to that class can break your
 class.



                                      Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: containment
 • The “Containment” relationship
 (also known as the “Composition” relationship)
 is a special case of the “use” relationship.


 • In a Containment / Composition relationship,
 at least one method of one class actually contains an
 object of another class.




                                              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: containment

 ( In the use relationship, it calls methods of another object.)

                                           Account
          Order             message


 ( In the containment relationship, it contains another object.)

                            Order
                          Account
                                                Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: containment


 • In a “has-a” relationship, a class becomes an
 instance variable for the class we are defining.

     public class Order extends Object
     {
          Account acct = new Account();




                                     Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: inheritance
 • Inheritance means specialization.


 • When we inherit from a class, we wish to keep nearly
 everything in the base class (Superclass).


 • In inheritance, we seek to elaborate on what we receive
 from the Superclass.



                                             Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: inheritance
 • We start with the class Order.


 • Then, we wish to create a Subclass off of Order.


 • Our Subclass is called RushOrder.




                                            Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes: inheritance
 • Class RushOrder has everything that Order has, but it:

       -adds a few instance variables, maybe
       -adds a method or two and
       -overrides a method or two.




                                               Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Relationships Between Classes
 • These three relationships between classes form the
 foundation of Object-Oriented Design.


        use

       “has-a”

       “is-a”
                                             Java I—Copyright © 2000 Tom Hunter
Techniques
     for
Using Objects


            Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Techniques for Using Objects

 • We have spent a lot of time emphasizing the difference
 between a reference and the object to which it refers.

       JLabel howdy;
       howdy = new JLabel( “How Are Ya?” );




                                            Java I—Copyright © 2000 Tom Hunter
JLabel howdy; = new JLabel( “How Are Ya?” );
           howdy
 howdy


                               “How are Ya?”



• We start off by declaring a reference “howdy” to an object
of type JLabel.

• Then, we instantiate the object by calling its constructor
with the new keyword, and assign the handle to this
instantiation to the reference we declared: “howdy”.

                                             Java I—Copyright © 2000 Tom Hunter
howdy = new JLabel( “How Are Ya?” );
   howdy


   hello                           “How are Ya?”


 • Okay, what happens when I do the following statement?
       JLabel hello; // A new reference

        hello = howdy;
• Now, both references point to the exact same object.

• Any changes made from howdy will be reflected in hello.
                                              Java I—Copyright © 2000 Tom Hunter
Controlling
       Access
         to
Methods and Variables

                Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Controlling Access to Methods: public

 • public—this lets clients see the services (methods) the
       class provides (which means view the interface.)

       —The interface is the collective name for all the
           various methods that are available in the class.

       —Methods should be public.




                                              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Controlling Access to Member Variables and
 Methods: public & private

 • private

    —It hides implementation details.

   — Private data members (variables) are only accessible
      through the public interface (Accessor methods)
      using public methods. (getter and Setter).




                                           Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
  Controlling Access to Member: package

  • package—if you don’t specify that a method or a
        data variable is either private or public, then
        when you have automatically given it
        package access.

  • If your program has only one class definition—this
         change is transparent. It has zero effect.

        H O W E V E R...


                                              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
  Controlling Access to Member: package

  • if you don’t specify either public or private for any
  feature…

        [ meaning class, method or variable ]

  can be accessed by all methods in the
  same package!



                                              Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Controlling Access to Member: package

  • So, if you have the following field in your class:

  public class MyClass
  {
       int mySalary;
  …
  }
  … and your class is stored in java.util.*;
       then any other method in any class that is also
       stored in this package can change this variable
       to anything it wants. No methods needed!

                                               Java I—Copyright © 2000 Tom Hunter
OOP Vocabulary
 Creating a Package

 • A package is a way to organize classes.

 • Normally, you create a public class.

 • If you don’t define your class as public, then it’s only
        accessible to other classes in the same package.




                                                Java I—Copyright © 2000 Tom Hunter
Access Levels

Modifier   Class Package Subclass World

Public     Y    Y        Y        Y

Protected Y     Y        Y        N

no         Y    Y        N        N
modifier
Private    Y    N        N        N



                                Java I—Copyright © 2000 Tom Hunter
Objects Passed By
   Reference



               Java I—Copyright © 2000 Tom Hunter
Object-Based Programming
Objects Passed By Reference

• As we know the name or reference for an object
      represents a memory location
      where the object is stored.


• When an object is passed, only the reference is passed.




                                             Java I—Copyright © 2000 Tom Hunter
Object-Based Programming
Objects Passed By Reference

• That means, only the address of the object is passed.


• A copy is NOT made of the object.


• This will have interesting implications.




                                             Java I—Copyright © 2000 Tom Hunter
Creating Our
        First
    Class Object
Class – Object – Constructor – static




                             Java I—Copyright © 2000 Tom Hunter
The this
Reference


            Java I—Copyright © 2000 Tom Hunter
The this Reference
• You were sitting in your Ferrarri in your driveway.
• Next door, your plumber neighbor was sitting in her
Ferrarri.
• If you wanted to refer to your neighbor’s Ferrarri, you
would naturally say “Jane’s Ferrarri….”
• Likewise, it would be perfectly natural for you to refer
to the car you were sitting in as “this Ferrarri….”



                                            Java I—Copyright © 2000 Tom Hunter
The this Reference
• “this Ferrarri….”


• In Java, the this reference is used to refer to the object
you are inside of at this moment.


• We say that each object has a reference to itself—called
the this reference.




                                            Java I—Copyright © 2000 Tom Hunter
The this Reference
• The this reference is used to refer to both the instance
variables and methods of an object.
• In Event Handlers, we have used the this reference to
show that this Applet (and by implication this
Applet’s actionPerformed method) will listen for
events from this object.


• The this reference can also be used for cascading
method calls which allow a reference to be passed back
up the calling chain.

                                           Java I—Copyright © 2000 Tom Hunter

More Related Content

What's hot

Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS abhishek kumar
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingAmit Soni (CTFL)
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programmingSachin Sharma
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Editionmoxuji
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
Principal of objected oriented programming
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming Rokonuzzaman Rony
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationshipsPooja mittal
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming conceptsrahuld115
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Basic oop concepts - C++
Basic oop concepts - C++Basic oop concepts - C++
Basic oop concepts - C++Aleena Varghese
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++ Hridoy Bepari
 

What's hot (20)

Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Edition
 
Data types in java
Data types in javaData types in java
Data types in java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Principal of objected oriented programming
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming concepts
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Basic oop concepts - C++
Basic oop concepts - C++Basic oop concepts - C++
Basic oop concepts - C++
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 

Viewers also liked

Oop Overview
Oop OverviewOop Overview
Oop Overviewphananhvu
 
Very short OOP Introduction
Very short OOP IntroductionVery short OOP Introduction
Very short OOP IntroductionCristian G
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionKent Huang
 
Redis training for java software engineers
Redis training for java software engineersRedis training for java software engineers
Redis training for java software engineersMoshe Kaplan
 
Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...Mario Gleichmann
 
Empathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible codeEmpathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible codeMario Gleichmann
 
Writing beautiful code with Java 8
Writing beautiful code with Java 8Writing beautiful code with Java 8
Writing beautiful code with Java 8Sergiu Mircea Indrie
 
Simply - OOP - Simply
Simply - OOP - SimplySimply - OOP - Simply
Simply - OOP - SimplyThomas Bahn
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code DevelopmentPeter Gfader
 
Clean Code (Presentacion interna en Virtual Software)
Clean Code (Presentacion interna en Virtual Software)Clean Code (Presentacion interna en Virtual Software)
Clean Code (Presentacion interna en Virtual Software)jmiguel rodriguez
 
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Nikita Koksharov
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examplesagni_agbc
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?Colin Riley
 

Viewers also liked (20)

Oop Overview
Oop OverviewOop Overview
Oop Overview
 
Very short OOP Introduction
Very short OOP IntroductionVery short OOP Introduction
Very short OOP Introduction
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
 
Ashish oot
Ashish ootAshish oot
Ashish oot
 
OOP vs COP
OOP vs COPOOP vs COP
OOP vs COP
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Redis training for java software engineers
Redis training for java software engineersRedis training for java software engineers
Redis training for java software engineers
 
Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...
 
Empathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible codeEmpathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible code
 
Writing beautiful code with Java 8
Writing beautiful code with Java 8Writing beautiful code with Java 8
Writing beautiful code with Java 8
 
Simply - OOP - Simply
Simply - OOP - SimplySimply - OOP - Simply
Simply - OOP - Simply
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Clean Code (Presentacion interna en Virtual Software)
Clean Code (Presentacion interna en Virtual Software)Clean Code (Presentacion interna en Virtual Software)
Clean Code (Presentacion interna en Virtual Software)
 
Clean Code
Clean CodeClean Code
Clean Code
 
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 

Similar to OOP Basics

Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
 
introduction of Object oriented programming
introduction of Object oriented programmingintroduction of Object oriented programming
introduction of Object oriented programmingRiturajJain8
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOPMuhammad Hammad Waseem
 
Voyage by example
Voyage by exampleVoyage by example
Voyage by exampleESUG
 
Object oriented java script
Object oriented java scriptObject oriented java script
Object oriented java scriptvivek p s
 
Intro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CIntro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CAndrew Rohn
 
Method Swizzling with Objective-C
Method Swizzling with Objective-CMethod Swizzling with Objective-C
Method Swizzling with Objective-CAdamFallon4
 
OOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxOOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxuzairrrfr
 
OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)Ashoka R K T
 
introduction_OO.pptx
introduction_OO.pptxintroduction_OO.pptx
introduction_OO.pptxMonishaAb1
 
unit 1 full ppt.pptx
unit 1 full ppt.pptxunit 1 full ppt.pptx
unit 1 full ppt.pptxthenmozhip8
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureManish Jangir
 
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15Raunak Talwar
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 

Similar to OOP Basics (20)

Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
introduction of Object oriented programming
introduction of Object oriented programmingintroduction of Object oriented programming
introduction of Object oriented programming
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
 
Voyage by example
Voyage by exampleVoyage by example
Voyage by example
 
OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Object oriented java script
Object oriented java scriptObject oriented java script
Object oriented java script
 
java - oop's in depth journey
java - oop's in depth journeyjava - oop's in depth journey
java - oop's in depth journey
 
Intro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CIntro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-C
 
Method Swizzling with Objective-C
Method Swizzling with Objective-CMethod Swizzling with Objective-C
Method Swizzling with Objective-C
 
OOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxOOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptx
 
OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)OOPs fundamentals session for freshers in my office (Aug 5, 13)
OOPs fundamentals session for freshers in my office (Aug 5, 13)
 
introduction_OO.pptx
introduction_OO.pptxintroduction_OO.pptx
introduction_OO.pptx
 
introduction_OO.pptx
introduction_OO.pptxintroduction_OO.pptx
introduction_OO.pptx
 
unit 1 full ppt.pptx
unit 1 full ppt.pptxunit 1 full ppt.pptx
unit 1 full ppt.pptx
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
 
OOP in JS
OOP in JSOOP in JS
OOP in JS
 
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

OOP Basics

  • 1. Great Introduction to OOP Prepared by : Tom Hunter Edited and Updated By:Mohamed Shahpoup Java I—Copyright © 2000 Tom Hunter
  • 2. 1- Introduction. 2- What is OOP. 3- OOP Vocabulary . 4- Creating Our First Class Object. 5- Using this Keyword. Java I—Copyright © 2000 Tom Hunter
  • 3. The Genius of Using Objects • How did companies like Dell, Compaq and Gateway get so big? • They bought components from other companies and assembled the pieces into their products. Java I—Copyright © 2000 Tom Hunter
  • 4. The Genius of Using Objects • Dell didn’t design its own motherboards. • Compaq didn’t engineer its own hard drives or operating systems. • They bought the pieces and let somebody else do the engineering. Java I—Copyright © 2000 Tom Hunter
  • 5. The Genius of Using Objects • Dell, Compaq and Gateway let somebody else reinvent the power supply or the motherboard. • Object-Oriented programming is the same idea. • A program is composed of generic objects, with certain standard properties, and certain standard operations the objects can perform. Java I—Copyright © 2000 Tom Hunter
  • 6. The Genius of Using Objects • Dell doesn’t care how the power supply works. • Dell cares if the power supply works. • How the power supply works is hidden and private. • Only the end result is visible. Java I—Copyright © 2000 Tom Hunter
  • 7. The Genius of Using Objects • Dell is only exposed to the end result. • Most important is the power supply’s public face— the power. • Dell doesn’t care how it works internally. Java I—Copyright © 2000 Tom Hunter
  • 8. The Genius of Using Objects • Likewise, in OOP, you only care about what the objects expose. • You can’t know how somebody else’s object works. Java I—Copyright © 2000 Tom Hunter
  • 9. The Genius of Using Objects • You don’t care how the JOptionPane works. • You care about its public methods—its “interface”. You only care about its public methods ! Java I—Copyright © 2000 Tom Hunter
  • 10. The Genius of Using Objects • In traditional procedural programming, you search for verbs in the problem definition. • In procedural programming, the verbs directly suggest procedures and then, lastly, you think of data variables to go with those procedures. Java I—Copyright © 2000 Tom Hunter
  • 11. The Genius of Using Objects • In OOP, you put data structures first, and then look at the algorithms that operate on the data. Java I—Copyright © 2000 Tom Hunter
  • 12. The Genius of Using Objects • The secret to effective OOP: Each object carries out a small set of related tasks. If an object needs a task done—but that task isn’t the job of that object—then that object asks another object to do the task. “If I can’t do it, then I’ll ask somebody who can.” Java I—Copyright © 2000 Tom Hunter
  • 13. The Genius of Using Objects • Again, since the first object can’t do the task, it asks the second object to carry out the task. • In OOP jargon, we say: “A Client object sends a message to a Server object.” Java I—Copyright © 2000 Tom Hunter
  • 14. The Genius of Using Objects • In OOP, one object must never directly manipulate the internal data of another object. encapsulation • Rather, all communication is through “messages”. (A message is another name for a method call.) Java I—Copyright © 2000 Tom Hunter
  • 15. The Genius of Using Objects • When you design your object to hide how it handles requests... (messages / method calls) ...you make it easily reusable. Java I—Copyright © 2000 Tom Hunter
  • 16. The Genius of Using Objects • When you see a Windows OS computer lock up, and you do a CTRL-ALT-DEL, the “Close Program” window that pops up might say: (Not Responding) • That message means that some Windows object is not responding to messages. • Some program called a method, but Windows failed to respond. (No surprise) Java I—Copyright © 2000 Tom Hunter
  • 17. OOP Vocabulary Class Java I—Copyright © 2000 Tom Hunter
  • 18. OOP Vocabulary class • The term class is the blueprint which the object is actually made, or “instantiated.” MyClass boop; boop = new MyClass(); We are now familiar with this: The first “MyClass boop; ” makes a reference called “boop.” Java I—Copyright © 2000 Tom Hunter
  • 19. OOP Vocabulary MyClass boop; At this point, the reference called “boop” does not actually point to any existing object. Soon, it will point to an object of type MyClass, but now the object doesn’t exist. Java I—Copyright © 2000 Tom Hunter
  • 20. OOP Vocabulary MyClass boop = new MyClass(); When this statement executes, the new keyword executes the default Constructor for MyClass, which actually creates an object in memory and assigns that reference to boop. The handle to that just-created object is given to the MyClass reference boop. Now boop points to the new MyClass object. Java I—Copyright © 2000 Tom Hunter
  • 21. state behavior identity Java I—Copyright © 2000 Tom Hunter
  • 22. OOP Vocabulary state behavior identity • Each object in OOP has three key characteristics: What? How? Who? Java I—Copyright © 2000 Tom Hunter
  • 23. OOP Vocabulary state behavior identity • Key characteristics: (What) What is the object’s state? (How) What is the object’s behavior? (Who) What is the object’s identity? Java I—Copyright © 2000 Tom Hunter
  • 24. OOP Vocabulary state behavior identity • All instances of a class have the same instance variables, but of course those variables have different values inside them. • The state—or current values—for an instance of a class, is called the “state” of that class. • The current values of those variables define the current situation or state of this instance of the class. Java I—Copyright © 2000 Tom Hunter
  • 25. OOP Vocabulary state behavior identity • For example, if I have a class called HourlyEmployee, then it contains instance variables: first_name last_name soc_sec_number hourly_rate current_vacation_time Java I—Copyright © 2000 Tom Hunter
  • 26. OOP Vocabulary state behavior identity • All objects that are instances of the same class share the same behavior. • They all have the same methods. Java I—Copyright © 2000 Tom Hunter
  • 27. OOP Vocabulary state behavior identity • My class is: HourlyEmployee • All instances of this class have these methods: calculate_pay() setName() Methods getName() setSSN() getSSN() getVacationTime() setVacationTime() getHourlyRate() setHourlyRate() Java I—Copyright © 2000 Tom Hunter
  • 28. OOP Vocabulary state behavior identity • My class is: HourlyEmployee • Every example, or instantiation, of this class has the same methods (behavior) available to it. Java I—Copyright © 2000 Tom Hunter
  • 29. OOP Vocabulary state behavior identity • My class is: HourlyEmployee • Let’s instantiate HourlyEmployee : HourlyEmployee joseph; // empty reference. joseph = new HourlyEmployee(‘Joe’,’Smith’, ’598-22-7893’,’$10.00’,’22.25’); • Now, I have created an instance of the class HourlyEmployee. Java I—Copyright © 2000 Tom Hunter
  • 30. OOP Vocabulary state behavior identity • My class is: HourlyEmployee • I have instantiated HourlyEmployee. • My instance is called joseph. • The identity of my instance is joseph. Java I—Copyright © 2000 Tom Hunter
  • 31. OOP Vocabulary state behavior identity • The identity of my instance is joseph. • The state of my instance is: first_name = ‘Joe’ last_name = ’Smith’ soc_sec_number = ’598-22-7893’ hourly_rate = ’$10.00’ current_vacation_time = ’22.25’ • The behavior of my instance is: calculate_pay() setName() getName() setSSN() getSSN() Java I—Copyright © 2000 Tom Hunter
  • 32. OOP Vocabulary identity for each of the three. Tell me the state behavior identity • Now, I will instantiate three objects: HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); HourlyEmployee theodore; theodore = new HourlyEmployee(‘Ted’,’L.’, ’681-22-9875’,’$10.00’,’22’); HourlyEmployee david; david = new HourlyEmployee(‘Dave’,’D.’, ’198-99-0098’,’$15.00’,’8’); Java I—Copyright © 2000 Tom Hunter
  • 33. OOP Vocabulary state behavior identity • Identity is the reference to this instantiation. HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); HourlyEmployee theodore; theodore = new HourlyEmployee(‘Ted’,’L.’, ’681-22-9875’,’$10.00’,’22’); HourlyEmployee david; david = new HourlyEmployee(‘Dave’,’D.’, ’198-99-0098’,’$15.00’,’8’); Java I—Copyright © 2000 Tom Hunter
  • 34. OOP Vocabulary behaviors for each of the three. Tell me the state behavior identity HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); HourlyEmployee theodore; theodore = new HourlyEmployee(‘Ted’,’L.’, ’681-22-9875’,’$10.00’,’22’); HourlyEmployee david; david = new HourlyEmployee(‘Dave’,’D.’, ’198-99-0098’,’$15.00’,’8’); Java I—Copyright © 2000 Tom Hunter
  • 35. OOP Vocabulary state behavior identity • All three have the exact same behaviors. HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); HourlyEmployee theodore; theodore = new HourlyEmployee(‘Ted’,’L.’, ’681-22-9875’,’$10.00’,’22’); HourlyEmployee david; david = new HourlyEmployee(‘Dave’,’D.’, ’198-99-0098’,’$15.00’,’8’); Java I—Copyright © 2000 Tom Hunter
  • 36. OOP Vocabularythe state for each of the three. Tell me state behavior identity HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); HourlyEmployee theodore; theodore = new HourlyEmployee(‘Ted’,’L.’, ’681-22-9875’,’$10.00’,’22’); HourlyEmployee david; david = new HourlyEmployee(‘Dave’,’D.’, ’198-99-0098’,’$15.00’,’8’); Java I—Copyright © 2000 Tom Hunter
  • 37. OOP Vocabulary state behavior identity • The state of each instance is defined by its instance variables. HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); HourlyEmployee theodore; theodore = new HourlyEmployee(‘Ted’,’L.’, ’681-22-9875’,’$10.00’,’22’); HourlyEmployee david; david = new HourlyEmployee(‘Dave’,’D.’, ’198-99-0098’,’$15.00’,’8’); Java I—Copyright © 2000 Tom Hunter
  • 38. OOP Vocabulary state behavior identity • The state of an instance can only be changed by going through its methods or behaviors. HourlyEmployee marie; marie = new HourlyEmployee(‘Mary’,’J.’, ’555-24-1516’,’$30.00’,’0’); marie.setSSN( ‘444-33-1264’ ); Java I—Copyright © 2000 Tom Hunter
  • 39. Class Scope Java I—Copyright © 2000 Tom Hunter
  • 40. OOP Vocabulary Class Scope • A class’s Instance variables and methods have a thing called “class scope.” • Within the class (within the scope of that class), class member variables are accessible by name. (static Members) • So, inside or outside of any method in that class, those instance variables can be reached from anywhere in the class. Java I—Copyright © 2000 Tom Hunter
  • 41. OOP Vocabulary Class Scope • If a member variable has been (foolishly) declared public, then it can be accessed outside of the class by simply referencing as follows: ClassName.primitive_variable ClassName.Object_variable. • Another instance of this class has access to the instance variables in any other instance of this class. • You can use the instance identifier or the class name if it is declared as a “static” variable. Java I—Copyright © 2000 Tom Hunter
  • 42. Cosmic Base Class Java I—Copyright © 2000 Tom Hunter
  • 43. OOP Vocabulary Cosmic Base Class • In Java, all classes are built on other classes. • We say, that one class extends another class. • Ultimately, all classes in Java stem from one central “Cosmic Base Class” called Object. • Even if you didn’t use the word “extends” in your class definition, you were still always extending Object by default. Java I—Copyright © 2000 Tom Hunter
  • 44. OOP Vocabulary Base Class • When you extend any “Base Class”, the new (derived) class has all the properties ( instance variables) and methods of its parent, or Base Class. • You can choose to modify or keep any method of the parent, or you can create methods that only apply to the child or “inherited” class. Java I—Copyright © 2000 Tom Hunter
  • 45. Inheritance Java I—Copyright © 2000 Tom Hunter
  • 46. OOP Vocabulary Inheritance • The concept of extending a base class is called “Inheritance.” • Inheritance is the second fundamental concept of Object-Oriented programming. (Encapsulation is the first, Polymorphism is the third) Java I—Copyright © 2000 Tom Hunter
  • 47. OOP Vocabulary Relationships Between Classes • Classes can be related to each other in one of three alternative ways: use containment ( “has-a” ) inheritance ( “is-a” ) Java I—Copyright © 2000 Tom Hunter
  • 48. OOP Vocabulary • When one class sends messages to another class, we say it “uses” the class that receives its messages. Use Java I—Copyright © 2000 Tom Hunter
  • 49. OOP Vocabulary • When one class lives as an Instance Variable within another class, we say it is “Contained”, a “has-a” relationship. Containment ( “has-a” ) Java I—Copyright © 2000 Tom Hunter
  • 50. OOP Vocabulary • When one class inherits from another class, we say it is an “is-a” relationship. inheritance ( “is-a” ) Java I—Copyright © 2000 Tom Hunter
  • 51. OOP Vocabulary Relationships Between Classes: use • Imagine that we have a class Order. • Class Order needs to use the class Account, in order to check for credit status. Java I—Copyright © 2000 Tom Hunter
  • 52. OOP Vocabulary Relationships Between Classes: use • Generally, if a method of class Order sends a message to an object of class Account, then Order uses Account. Account Order message • In other words, Order uses Account when Order calls methods of Account. Java I—Copyright © 2000 Tom Hunter
  • 53. OOP Vocabulary Relationships Between Classes: use • Also, we say class Order uses class Account if: • A method of Order : creates receives or returns objects of class Account . Java I—Copyright © 2000 Tom Hunter
  • 54. OOP Vocabulary Relationships Between Classes: use • Design Tip: Avoid the “use” relationship whenever you can. If you “use” somebody else’s class, then any changes to that class can break your class. Java I—Copyright © 2000 Tom Hunter
  • 55. OOP Vocabulary Relationships Between Classes: containment • The “Containment” relationship (also known as the “Composition” relationship) is a special case of the “use” relationship. • In a Containment / Composition relationship, at least one method of one class actually contains an object of another class. Java I—Copyright © 2000 Tom Hunter
  • 56. OOP Vocabulary Relationships Between Classes: containment ( In the use relationship, it calls methods of another object.) Account Order message ( In the containment relationship, it contains another object.) Order Account Java I—Copyright © 2000 Tom Hunter
  • 57. OOP Vocabulary Relationships Between Classes: containment • In a “has-a” relationship, a class becomes an instance variable for the class we are defining. public class Order extends Object { Account acct = new Account(); Java I—Copyright © 2000 Tom Hunter
  • 58. OOP Vocabulary Relationships Between Classes: inheritance • Inheritance means specialization. • When we inherit from a class, we wish to keep nearly everything in the base class (Superclass). • In inheritance, we seek to elaborate on what we receive from the Superclass. Java I—Copyright © 2000 Tom Hunter
  • 59. OOP Vocabulary Relationships Between Classes: inheritance • We start with the class Order. • Then, we wish to create a Subclass off of Order. • Our Subclass is called RushOrder. Java I—Copyright © 2000 Tom Hunter
  • 60. OOP Vocabulary Relationships Between Classes: inheritance • Class RushOrder has everything that Order has, but it: -adds a few instance variables, maybe -adds a method or two and -overrides a method or two. Java I—Copyright © 2000 Tom Hunter
  • 61. OOP Vocabulary Relationships Between Classes • These three relationships between classes form the foundation of Object-Oriented Design. use “has-a” “is-a” Java I—Copyright © 2000 Tom Hunter
  • 62. Techniques for Using Objects Java I—Copyright © 2000 Tom Hunter
  • 63. OOP Vocabulary Techniques for Using Objects • We have spent a lot of time emphasizing the difference between a reference and the object to which it refers. JLabel howdy; howdy = new JLabel( “How Are Ya?” ); Java I—Copyright © 2000 Tom Hunter
  • 64. JLabel howdy; = new JLabel( “How Are Ya?” ); howdy howdy “How are Ya?” • We start off by declaring a reference “howdy” to an object of type JLabel. • Then, we instantiate the object by calling its constructor with the new keyword, and assign the handle to this instantiation to the reference we declared: “howdy”. Java I—Copyright © 2000 Tom Hunter
  • 65. howdy = new JLabel( “How Are Ya?” ); howdy hello “How are Ya?” • Okay, what happens when I do the following statement? JLabel hello; // A new reference hello = howdy; • Now, both references point to the exact same object. • Any changes made from howdy will be reflected in hello. Java I—Copyright © 2000 Tom Hunter
  • 66. Controlling Access to Methods and Variables Java I—Copyright © 2000 Tom Hunter
  • 67. OOP Vocabulary Controlling Access to Methods: public • public—this lets clients see the services (methods) the class provides (which means view the interface.) —The interface is the collective name for all the various methods that are available in the class. —Methods should be public. Java I—Copyright © 2000 Tom Hunter
  • 68. OOP Vocabulary Controlling Access to Member Variables and Methods: public & private • private —It hides implementation details. — Private data members (variables) are only accessible through the public interface (Accessor methods) using public methods. (getter and Setter). Java I—Copyright © 2000 Tom Hunter
  • 69. OOP Vocabulary Controlling Access to Member: package • package—if you don’t specify that a method or a data variable is either private or public, then when you have automatically given it package access. • If your program has only one class definition—this change is transparent. It has zero effect. H O W E V E R... Java I—Copyright © 2000 Tom Hunter
  • 70. OOP Vocabulary Controlling Access to Member: package • if you don’t specify either public or private for any feature… [ meaning class, method or variable ] can be accessed by all methods in the same package! Java I—Copyright © 2000 Tom Hunter
  • 71. OOP Vocabulary Controlling Access to Member: package • So, if you have the following field in your class: public class MyClass { int mySalary; … } … and your class is stored in java.util.*; then any other method in any class that is also stored in this package can change this variable to anything it wants. No methods needed! Java I—Copyright © 2000 Tom Hunter
  • 72. OOP Vocabulary Creating a Package • A package is a way to organize classes. • Normally, you create a public class. • If you don’t define your class as public, then it’s only accessible to other classes in the same package. Java I—Copyright © 2000 Tom Hunter
  • 73. Access Levels Modifier Class Package Subclass World Public Y Y Y Y Protected Y Y Y N no Y Y N N modifier Private Y N N N Java I—Copyright © 2000 Tom Hunter
  • 74. Objects Passed By Reference Java I—Copyright © 2000 Tom Hunter
  • 75. Object-Based Programming Objects Passed By Reference • As we know the name or reference for an object represents a memory location where the object is stored. • When an object is passed, only the reference is passed. Java I—Copyright © 2000 Tom Hunter
  • 76. Object-Based Programming Objects Passed By Reference • That means, only the address of the object is passed. • A copy is NOT made of the object. • This will have interesting implications. Java I—Copyright © 2000 Tom Hunter
  • 77. Creating Our First Class Object Class – Object – Constructor – static Java I—Copyright © 2000 Tom Hunter
  • 78. The this Reference Java I—Copyright © 2000 Tom Hunter
  • 79. The this Reference • You were sitting in your Ferrarri in your driveway. • Next door, your plumber neighbor was sitting in her Ferrarri. • If you wanted to refer to your neighbor’s Ferrarri, you would naturally say “Jane’s Ferrarri….” • Likewise, it would be perfectly natural for you to refer to the car you were sitting in as “this Ferrarri….” Java I—Copyright © 2000 Tom Hunter
  • 80. The this Reference • “this Ferrarri….” • In Java, the this reference is used to refer to the object you are inside of at this moment. • We say that each object has a reference to itself—called the this reference. Java I—Copyright © 2000 Tom Hunter
  • 81. The this Reference • The this reference is used to refer to both the instance variables and methods of an object. • In Event Handlers, we have used the this reference to show that this Applet (and by implication this Applet’s actionPerformed method) will listen for events from this object. • The this reference can also be used for cascading method calls which allow a reference to be passed back up the calling chain. Java I—Copyright © 2000 Tom Hunter

Editor's Notes

  1. White Space Characters
  2. White Space Characters
  3. White Space Characters
  4. White Space Characters
  5. White Space Characters
  6. White Space Characters
  7. White Space Characters
  8. White Space Characters
  9. White Space Characters
  10. White Space Characters
  11. White Space Characters
  12. White Space Characters
  13. White Space Characters
  14. White Space Characters