A couple of practice problems as a class

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

Object Oriented Programming with Java
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
Revision.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
OOP: Inheritance By: Lamiaa Said.
Lecture 28: Abstract Classes & Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Read: –Chapter 9 Cahoon & Davidson.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
CS 1110 Final Exam: Review Session 2 Part 1 : Inheriting classes 1. Inheritance Facts 2. Constructors in Subclasses BREAK : 10 sec. Part 2 : Working with.
Inheritance #1 First questions Similar to Python? What about visibility and encapsulation? – can an object of the child class access private members.
Chapter 5 - Making Music: An On-Screen Piano
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
AP Computer Science A – Healdsburg High School 1 Interfaces and Abstract Classes - What are they? - How are they used? - Where will we use them? - Calling.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
A way to pull together related data A Shape Class would contain the following data: x, y, height, width Then associate methods with that data A Shape.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
ECE122 Feb. 22, Any question on Vehicle sample code?
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
Day 8: Fruit Loops: Color. Loop Review What does the following loop print? for (int i= 0; i
The Class Construct Defining objects with attributes and behavior JPC and JWD © 2002 McGraw-Hill, Inc.
CS 106 Introduction to Computer Science I 10 / 29 / 2007 Instructor: Michael Eckmann.
Inheritance (Part 2) Notes Chapter KomondorBloodHound PureBreedMix Dog Object Dog extends Object PureBreed extends Dog Komondor extends PureBreed.
Lecture 24: Color Announcements & Review Lab 7 Due Thursday 2 D arrays - embedding graphs in an array Computer Science Artifacts Abstraction Representations.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
PHY281 Scientific Java Programming ObjectsSlide 1 Classes & Objects In this section we will learn about Classes and Objects in Java :  What are Objects?
FRACTIONS & SHAPES BY:. How many of these are colored red? * out of *.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.4 Constructors, Overloading,
Welcome back!. Object Oriented Programming – Encapsulation Classes encapsulate state (fields) and behavior (methods) – Polymorphism Signature Polymorphism.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
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 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Final and Abstract Classes
CMPUT 301: Lecture 06 Interfaces, Abstract classes and Inheritance
Defining objects with attributes and behavior
Chapter 3: Using Methods, Classes, and Objects
INHERITANCE IN JAVA.
Class Inheritance (Cont.)
Interface.
Java Inheritance.
Clicker quiz 10/15/13 CSE 1102 Fall 2013.
Interfaces.
C++ Interlude 1 C++ Classes
Fractions 1/2 1/8 1/3 6/8 3/4.
Announcements & Review
Inheritance Inheritance is a fundamental Object Oriented concept
Java Programming, Second Edition
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
What Color is it?.
Inheritance in Java CS 3331 Fall 2009.
Java Programming with BlueJ Objectives
Object Oriented Programming
Object Oriented Programming
IAT 800 Foundations of Computational Art and Design
Anatomy of Inheritance
Color Box Button - Gray Type : object Type : object Type : object
Java Inheritance.
Chapter 11 Classes.
Let’s Learn the Basic Colors
Counting 10s = 10 How many? Count and write number.
Presentation transcript:

A couple of practice problems as a class AP Java 3/4/2019 Inheritance Review A couple of practice problems as a class Practice Midterm.

Under Construction: The flow of constructors 1) Client class calls new() to start construction MyClass x = new MyClass(stuff); 2) Object class determines which constructor to use based on the arguments of new MyClass(stuff) public MyClass(String newStuff) {} 3) If there is super() call in the constructor then the parent’s matching constructor. 4) If there is no super() call it implicitly calls the parent default (no arguments) constructor 5) It completes the MyClass constructor

The following statements occur in a client method: public class ColorBox { public ColorBox() System.out.print("black "); } public void showColor() System.out.print("red "); public class BlueGreenBox extends ColorBox public BlueGreenBox() System.out.print("blue "); super.showColor(); System.out.print("green "); The following statements occur in a client method:   ColorBox box = new BlueGreenBox(); box.showColor(); What is printed when these two lines are executed? A. black red B. blue green C. blue red green D. blue black red green E. black blue red green

public class Location { public Location(int xCoord, int yCoord) public class Location { public Location(int xCoord, int yCoord) . . . } public class Color public Color(int redVal, int greenVal, int blueVal) public class Widget private Location myLoc; public Widget(int x, int y) myLoc = new Location(x, y); public class Thingy extends Widget private Color myColor; public Thingy(int x, int y, Color col) super(x, y); myColor = col; Assume that the following statement appears in a client program. Widget widg = new Thingy(100, 100, new Color(100, 100, 100)); Which of the following best describes the order on which the constructors will complete execution? A. Color, Location, Widget, Thingy B. Widget, Thingy, Location, Color C. Color, Widget, Location, Thingy D. Thingy, Color, Widget, Location E. Color, Thingy, Location, Widget