03 objects and classes   in java
Upcoming SlideShare
Loading in...5
×
 

03 objects and classes in java

on

  • 435 views

 

Statistics

Views

Total Views
435
Views on SlideShare
435
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    03 objects and classes   in java 03 objects and classes in java Presentation Transcript

    • 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