Download presentation
Presentation is loading. Please wait.
1
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-1 Thinking in Objects u Analogies: Legos, PCs u Components u Assemblies u Defined interfaces and abstraction
2
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-2 Objects and Classes u Class u Instance
3
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-3 Behavior and Attributes u Instance variables define object attributes u Instance methods are functions that operate on object attributes
4
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-4 Class Creation (1) class Motorcycle { String make; String color; String engineState; void startEngine() { if (engineState == true) System.out.println(“Already on.”); else { engineState = true; System.out.println(“Now on.”); }
5
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-5 Class Creation (2) void showAtts() { System.out.println(“A “ + color + “ “ + make); if (engineState == true) System.out.println(“Engine on.”); else System.out.println(“Engine off.”); }
6
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-6 Class Creation (3) public static void main(String args[]) { Motorcycle m = new Motorcycle(); m.make = “Yamaha RZ350”; m.color = “yellow”; m.showAtts(); m.startEngine(); m.showAtts(); m.startEngine(); }
7
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-7 Inheritance u Subclass u Superclass u Inheritance of instance variables and methods
8
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-8 Class Hierarchy Design Examples u Vehicles (Lemay) u Computers u Sports u Desserts
9
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-9 Inheritance u Overriding methods u Multiple inheritance prohibited
10
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-10 Interfaces and Packages u Interface: a collection of methods without definitions, used to indicate special additional methods beyond those inherited by a class from its parent(s) u Packages: a collection of classes and related interfaces –java.lang –Package and class names (e.g., java.awt.Color)
11
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-11 Subclasses and Subclassing (1) import java.awt.Graphics; import java.awt.Font; import java.awt.Color; public class HelloAgainApplet extends java.applet.Applet { Font f = new Font(“TimesRoman”, Font.BOLD, 36); public void paint(Graphics g) { g.setFont(f); g.setColor(Color.red); g.drawString(“Hi!”, 5, 50); }
12
Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-12 Subclasses and Subclassing (2) Another Applet My second Java applet says:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.