Lecture_02_2 - ENGR 2200U UOIT/FEAS Fall 2007 ENGR 2710U OO...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ENGR 2200U UOIT/FEAS Fall 2007 © Mike Eklund ENGR 2710U OO Programming and Design 1 Using Objects II Using Objects II Professor Saman Kumarawadu ENGR 2710U Fall 2010 – Saman Kumarawadu ENGR 2710U OO Programming and Design Objectives • To construct an object • To understand Java Class Libraries • To realize the difference between objects and object references ENGR 2710U Fall 2010 – Saman Kumarawadu
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENGR 2200U UOIT/FEAS Fall 2007 © Mike Eklund ENGR 2710U OO Programming and Design OOP- Classes • Object oriented programming you create a model for a real world system. • Classes are programmer-defined types that model the parts of the system. • A class is a programmer defined type that serves as a blueprint for instances of the class. You can still have ints, floats, Strings, and arrays; but you can also have cars, people, buildings, clouds, dogs, angles, bank accounts, and any other type. • Classes specify the data and behavior possessed both by themselves and by the objects built from them. • A class has two parts: the fields and the methods. Fields describe what the class is. Methods describe what the class does. ENGR 2710U OO Programming and Design Objects • Using the blueprint provided by a class, you can create any number of objects, each of which is called an instance of the class. • Different objects of the same class have the same fields and methods, but the values of the fields will in general differ. • For example, all people have eye color; but the color of each person's eyes can be different from others.
Background image of page 2
ENGR 2200U UOIT/FEAS Fall 2007 © Mike Eklund ENGR 2710U OO Programming and Design Objects • Objects have the same methods as all other objects in the class and the methods depend on the value of the fields and arguments to the method. • This dichotomy is reflected in the runtime form of objects. • Every object has a separate block of memory to store its fields. ENGR 2710U OO Programming and Design Class Suppose you need to write a traffic simulation program that watches cars going past an intersection. Each car has a speed, a maximum speed, and a license plate that uniquely identifies it. In traditional programming languages you'd have two floating point and one string variable for each car. With a class you combine these into one thing like this. class Car { String licensePlate; // e.g. "New York 543 A23" double speed; // in kilometers per hour double maxSpeed; // in kilometers per hour } These variables (licensePlate, speed and maxSpeed) are called the member variables , instance variables , or fields of the class. Fields tell you what a class is and what its properties are. An
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

Lecture_02_2 - ENGR 2200U UOIT/FEAS Fall 2007 ENGR 2710U OO...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online