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.

Slides:



Advertisements
Similar presentations
Reusable Classes.  Motivation: Write less code!
Advertisements

Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
OOP & JAVA. HelloWorld.java /** * The HelloWorld class is an application that * displays "Hello World!" to the standard output. */ public class HelloWorld.
CSCI 143 OOP – Inheritance 1. What is Inheritance? A form of software reuse Create a new class from an existing class – Absorb existing class data and.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Inheritance using Java
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Arranging the border values of methods. import java.awt.*; import java.applet.Applet; public class Applet2 extends Applet { public void paint(Graphics.
CSC 142 Computer Science II Zhen Jiang West Chester University
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Inheritance. What Is Inheritance? Familiar examples: –A family tree (individuals inherit characteristics from other individuals) –A taxonomy (classes.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Pengantar OOP Class-Java. 2 Software Development Tools Using Sun Java SDK alone Source File(s) (.java) Programmer Compiler (javac) Class File(s) (.class)
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Coming up: Inheritance
Topics Inheritance introduction
Chapter 2 Creating a Java Application and Applet.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 7.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
Java Inheritance 1/13/2015. Learning Objectives Understand how inheritance promotes software reusability Understand notions of superclasses and subclasses.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Processing == Java + Extra Utilities Processing Adds: – Drawing functions – Text and font manipulations – Image and video – 3D transformations – Keyboard.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
User Interface Programming In Java
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Abstract classes and interfaces
Web Design & Development Lecture 9
Sections Inheritance and Abstract Classes
Lecture 12 Inheritance.
Lecture 6: Composition and Inheritance
Inheritance and Polymorphism
Interface.
Lecture 6: Composition and Inheritance
CSC 205 Java Programming II
Showing Relationships in UML
Advanced Java Programming
Abstract classes and interfaces
Interface.
Java Programming Language
Inheritance Inheritance is a fundamental Object Oriented concept
COMPUTER 2430 Object Oriented Programming and Data Structures I
Abstract classes and interfaces
Topics OOP Review Inheritance Review Abstract Classes
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

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

Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-2 Objects and Classes u Class u Instance

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

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.”); }

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.”); }

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(); }

Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-7 Inheritance u Subclass u Superclass u Inheritance of instance variables and methods

Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-8 Class Hierarchy Design Examples u Vehicles (Lemay) u Computers u Sports u Desserts

Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-9 Inheritance u Overriding methods u Multiple inheritance prohibited

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)

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); }

Azusa Pacific University CS 587: Java Lemay & Perkins [1996]2-12 Subclasses and Subclassing (2) Another Applet My second Java applet says: