1 / 6

CPSC 233 Tutorial

CPSC 233 Tutorial. Xin Feb 2, 2011. Scoping rules. Class Foo { int x ; // attribute, valid in the class ✓ Func1 (){ int x ; // shadowing ✗ int y = 0; // local variable. Valid here after till the end of Func1 ✓

acton
Télécharger la présentation

CPSC 233 Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPSC 233 Tutorial Xin Feb 2, 2011

  2. Scoping rules Class Foo { intx; // attribute, valid in the class ✓ Func1 (){ intx; // shadowing ✗ inty = 0; // local variable. Valid here after till the end of Func1 ✓ for (inti = 0; i < 3; i ++){ // i is local variable, valid in the for ✓ double k = y + 3; // local variable, valid in the for ✓ y += 3; // ✓ } i = 5; // ✗ Func2 (); // ✓ } Func2 () { // u = 3.0; // ✓ t = 5.f; //✗ float t; // ✓ } double u; // attribute, valid in the class ✓ }

  3. Associations • aggregation relationship (has-a relation) • public class Engine • { • public boolean ignite () { .. } • } • public class Car • { • private Engine anEngine; • private Light headLight; • public start () • { • anEngine.ignite (); • headLights.turnOn (); • } • } public class Light { private booleanisOn; public void turnOn () { isOn = true;} }

  4. Car Light Car Student Lecture Light Direction Bidirectional associations

  5. Car Light Car Owner Car Engine Multiplicity 10 1 1 * 1 1

  6. Assignment 2 Q&A • Due on Friday at 4 pm

More Related