03 objects and classes in java

492 views
442 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
492
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

03 objects and classes in java

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

×