KEMBAR78
03 objects and classes in java | PPT
Session 3 Object Oriented Programming Lecturer: Safa Nasir Session 3 Object-Oriented Programming
Using Third Party Classes Library of turtles that move around inside a virtual world.  The very first step to use this library/package is to create a world World worldObj = new World(); Creates a world object and allocate for it a space in memory. On Computer Demo  Session 3 Object-Oriented Programming 1 2 3 4
Which is the result of the following?  World worldObj = “earth”;  A string with the name “earth” is created A world with a name “earth” is created A world with the name “mars” is created None of the above Session 2 Object-Oriented Programming
Turtle World In this world i.e. worldObj we would like to put some turtles Turtle turtle2 = new Turtle(30,50,worldObj); Turtle(30,50,worldObj)  is a constructor that specifies three properties for the turtle2.  30, 50  specifies the location of  turtle2  in the  worldObj . Demo  Session 3 Object-Oriented Programming
What is a ‘Turtle’? Constructor Object Class String Session 2 Object-Oriented Programming
Using Turtle Capabilities The previous code performs the creation of the world and places a turtle in it.  Now we could use some capabilities of turtle2 to perform some useful tasks.  We will use the  dot notation  to invoke turtle2’s capabilities.  The dot notation will send a message to turtle to perform a specific task.  objectInstance . message ( paramterList ) Session 3 Object-Oriented Programming
Using Turtle Capabilities We would like turtle2 to move forward 20 units.  turtle2.forward(20); Session 3 Object-Oriented Programming
Using Turtle Capabilities We would like turtle2 to turn left. turtle2.turnLeft(); Session 3 Object-Oriented Programming
Readings Book Name:  Introduction to Computing and Programming in Java A Multimedia Approach Author:  Mark Guzdial and Barbara Ericson Content:  Chapter 3 Session 3 Object-Oriented Programming
Acknowledgements While preparing this course we have greatly benefited from the material developed by the following people: Dr. Naveed Arshad(LUMS) Andy Van Dam (Brown University) Mark Sheldon (Wellesley College) Robert Sedgewick and Kevin Wayne (Princeton University) Mark Guzdial and Barbara Ericsson (Georgia Tech) Richard Halterman (Southern Adventist University) Session 3 Object-Oriented Programming

03 objects and classes in java

  • 1.
    Session 3 ObjectOriented Programming Lecturer: Safa Nasir Session 3 Object-Oriented Programming
  • 2.
    Using Third PartyClasses Library of turtles that move around inside a virtual world. The very first step to use this library/package is to create a world World worldObj = new World(); Creates a world object and allocate for it a space in memory. On Computer Demo Session 3 Object-Oriented Programming 1 2 3 4
  • 3.
    Which is theresult of the following? World worldObj = “earth”; A string with the name “earth” is created A world with a name “earth” is created A world with the name “mars” is created None of the above Session 2 Object-Oriented Programming
  • 4.
    Turtle World Inthis world i.e. worldObj we would like to put some turtles Turtle turtle2 = new Turtle(30,50,worldObj); Turtle(30,50,worldObj) is a constructor that specifies three properties for the turtle2. 30, 50 specifies the location of turtle2 in the worldObj . Demo Session 3 Object-Oriented Programming
  • 5.
    What is a‘Turtle’? Constructor Object Class String Session 2 Object-Oriented Programming
  • 6.
    Using Turtle CapabilitiesThe previous code performs the creation of the world and places a turtle in it. Now we could use some capabilities of turtle2 to perform some useful tasks. We will use the dot notation to invoke turtle2’s capabilities. The dot notation will send a message to turtle to perform a specific task. objectInstance . message ( paramterList ) Session 3 Object-Oriented Programming
  • 7.
    Using Turtle CapabilitiesWe would like turtle2 to move forward 20 units. turtle2.forward(20); Session 3 Object-Oriented Programming
  • 8.
    Using Turtle CapabilitiesWe would like turtle2 to turn left. turtle2.turnLeft(); Session 3 Object-Oriented Programming
  • 9.
    Readings Book Name: Introduction to Computing and Programming in Java A Multimedia Approach Author: Mark Guzdial and Barbara Ericson Content: Chapter 3 Session 3 Object-Oriented Programming
  • 10.
    Acknowledgements While preparingthis course we have greatly benefited from the material developed by the following people: Dr. Naveed Arshad(LUMS) Andy Van Dam (Brown University) Mark Sheldon (Wellesley College) Robert Sedgewick and Kevin Wayne (Princeton University) Mark Guzdial and Barbara Ericsson (Georgia Tech) Richard Halterman (Southern Adventist University) Session 3 Object-Oriented Programming