Object Oriented Programming Lecture 5: BallWorld.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Advertisements

Abstract Classes We often define classes as subclasses of other classes – First, define the superclass – In some cases, a superclass may not have enough.
Inheritance Inheritance Reserved word protected Reserved word super
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Introduction to Data Structures, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Object Oriented Programming Concepts.
Object Oriented Concepts in Java Objects Inheritance Encapsulation Polymorphism.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
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.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
What is inheritance? It is the ability to create a new class from an existing class.
CSC 142 Computer Science II Zhen Jiang West Chester University
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
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.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Problem of the Day  What is the smallest positive integer that cannot be defined in less than twenty-five syllables?
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
BallWorld.java Ball.java A functional walkthrough Part 3: the interaction of objects.
Session 18 Lab 9 Re-cap, Chapter 12: Polymorphism & Using Sound in Java Applications.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Java exercise review Lesson 26: Exercise 4. Exercise #4 – a sample solution 1.Write the psudocode and the deployment diagram for what you are planning.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Inheritance Chapter 11 in Gaddis. Is a relationships in ‘real’ life Exist when one object is a specialized version of another one –Examples An english.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Object Oriented Programming Lecture 10: UML & CRC.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Review for Test2. Scope 8 problems, 60 points. 1 Bonus problem (5 points) Coverage: – Test 1 coverage – Exception Handling, Switch Statement – Array of.
A structured walkthrough
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Class Inheritance Part I
OOP: Encapsulation &Abstraction
Inheritance and Polymorphism
COP 3331 Object Oriented Analysis and Design Chapter 5 – Classes and Inheritance Jean Muhammad.
Object Oriented Programming
Can perform actions and provide communication
Inheritance Basics Programming with Inheritance
Can perform actions and provide communication
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Advanced Java Topics Chapter 9
Inherited Classes in Java
METHOD OVERRIDING in JAVA
Computer Programming with JAVA
Can perform actions and provide communication
Chapter 11 Inheritance and Polymorphism
Polymorphism Polymorphism - Greek for “many forms”
Java Programming, Second Edition
Inheritance CT1513.
Chapter 10: Method Overriding and method Overloading
Method Overriding and method Overloading
Presentation transcript:

Object Oriented Programming Lecture 5: BallWorld

Jargon Class / Instance Multiple instances of a Class Data fields Methods Class (Static) methods and fields (main) Inheritance (extends), super and sub classes Constructors – order of execution Constructor parameters (overloading)(super) Constants using ‘final’ modifier Accessor routines for fields (information hiding) Responsibilities and Secrets of Classes

Demonstration J03 program – Subclassing a Frame object to make BallWorld – Providing a constructor – Overloaded constructors with parameters – Calling the parent (super) class constructor – Creating multiple instances – Overriding ‘paint’ from the Frame class – The Graphics object for drawing J04 program – Having main in the ‘BallWorld’ (J04) class itself

Demonstration J05 program again – Making the drawing colour field ‘static’ leads to multiple BallWorld’s having the same drawing colour despite construction

Demonstration J06 program – Introduction of Ball class – Use of Rectangle for location – Use of ‘accessor’ routines to set and return fields – Use of ‘final’ fields as constants J06A program (modified in class) – Moving the responsibility from BallWorld to Ball for bouncing the Ball off the wall – Badly done in that the Frame size constants are copied into the Ball class

Exercises Chapter 5, page (You will need to read the chapter) – Questions 1-10 and 12 Chapter 5, page 82 – Exercises 1-3 – Exercise 4 Required program – is a version of the program developed from Exercise 4 which puts multiple balls into the BallWorld, starting with randomly chosen colours, speeds and directions. This should be verified this week.