Clicker questions 10/3/13 CSE 1102 Fall 2013.

Slides:



Advertisements
Similar presentations
So what's next? Introduction to data structures Two Perspectives: Abstract description (capabilities) Implementation(s) For structures: Stack Queue Deque.
Advertisements

Reusable Classes.  Motivation: Write less code!
Copyright © 2012 Pearson Education, Inc. Chapter 4 Inheritance and Polymorphism.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
Java Keywords CSE 115 Spring Purpose This set of slides contains a running list of the keywords that we have talked about so far this semester and.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Week 3 Recap CSE 115 – Spring Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are.
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Lecture 9 Polymorphism Richard Gesick.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
ECE122 Feb. 22, Any question on Vehicle sample code?
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Question of the Day  Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’ rope  $2.12 each Wire cutters  $4.49 each How.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Coming up: Inheritance
Clicker quiz 10/8/13 CSE 1102 Fall 2013 (E-30 reminder!)
When is a class not a class? When it is either abstract or an Interface.
Subclassing, pt. 2 Method overriding, virtual methods, abstract classes/methods COMP 401, Fall 2014 Lecture 9 9/16/2014.
Inheritance and Polymorphism
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Clicker questions 10/3/13 CSE 1102 Fall public class { … private _ ; public ) { … _ = ; … } … } In the above code, what is the purpose of the parameter.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Clicker quiz 10/1/13 CSE 1102 Fall public class Sun extends Ellipse { 2. public Sun(Color c) { 3. super(c); 4. … 5. } 6. public Sun() { 7. this(Color.yellow);
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Part -1 © by Pearson Education, Inc. All Rights Reserved.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Inheritance and Polymorphism
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Inheritance Notes: Using Object Oriented Design
Review What is an object? What is a class?
Interface, Subclass, and Abstract Class Review
Inheritance and Polymorphism
EKT 472: Object Oriented Programming
Agenda Warmup AP Exam Review: Litvin A2
Clicker quiz 10/1/13 CSE 1102 Fall 2013.
UML Class Diagram: class Rectangle
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
Interfaces.
Lecture 23 Polymorphism Richard Gesick.
Class Inheritance (Cont.)
MSIS 670 Object-Oriented Software Engineering
Lecture 22 Inheritance Richard Gesick.
Advanced Java Programming
The Java Alternative to Multiple Inheritance
Fundaments of Game Design
Abstract Classes and Interfaces
Agenda Inheritance Polymorphism Type compatibility Homework.
Abstract Classes and Interfaces
Computer Science II for Majors
Presentation transcript:

Clicker questions 10/3/13 CSE 1102 Fall 2013

public class <PartClass> { … private <ContainerClass> _<container>; public <PartClass(<ContainerClass> <aContainer>) { _<container> = <aContainer>; } public class HatPart { … private Hat _myHat; public HatPart(Hat aHat){ _myHat= aHat; } In the above code, what is the purpose of the parameter aHat? It sets a default value for _myHat object It is used to initialize _myHat when we instantiate a HatPart It is used to instantiate _myHat when we instantiate a HatPart It lets us change the value of _myHat in an existing HatPart instance All of the above In the above code, what is the purpose of the parameter <aContainer>? It sets a default value for _<container> object It is used to initialize _<container> when we instantiate a <PartClass> It is used to instantiate _<container> when we instantiate a <PartClass> It lets us change the value of _container in an existing <PartClass> instance All of the above

Notice from the diagram that Rectangle is not linked to Draggable Notice from the diagram that Rectangle is not linked to Draggable. What does this imply? HatPart must define all of the Draggable methods independent of Rectangle Someone forgot to put the link in the diagram Rectangle.java does not include the phrase implements Draggable Either A or B above Either B or C above

… OilTanker oily = new Truck(200); oily.move(); In the code above, which move method gets executed? The move method defined in OilTanker The move method defined in Truck The move method defined in Vehicle All of the above The code does not work

private Tree _tree; ... _tree = new Oak(); _tree.prepareForWinter(); Given the above class diagram, and the code on the right, what happens when the last line (_tree.prepareForWinter();) is executed? The prepareForWinter method defined in Oak is used The prepareForWinter method defined in Pine is used The prepareForWinter method defined in Tree is used The last line does not get executed since _tree = new Oak(); causes an error None of the above

public class Crow extends Bird { private Tree _myTree; ... public void battenDown(){ _myTree.??? } Suppose Russell is a Crow, and lives in an Oak. What can replace ??? above? prepareForWinter(); absorbWater(); dropLeaves(); Any public method from Tree or anything above it in the inheritance hierarchy Any public method from Oak or anything above it in the inheritance hierarchy

public class Oak extends Tree { ... public void prepareForWinter(){ this.dropLeaves(); ??? } Suppose an Oak prepares for winter like a Tree, but it drops its leaves first. What code should replace ??? above? Tree.prepareForWinter(); super.this(); super.prepareForWinter(); this.absorbWater(); super(this);

Example: Death Race 2000 Your task: to produce a new video game. It works by instantiating a DeathRace between 2 cars using the constructor, then calling its runTheRace method, which returns the winner. public class DeathRace { Car _car1, _car2; public DeathRace(Car c1,Car c2){ _car1 = c1; _car2 = c2; ... } public Car runTheRace(){ Car winner; _car1.move(); _car2.move(); return winner;

Car

public interface Holder { void add(Holdable h); Holdable release(); } public interface Holdable { Weight getWeight); Dimension getDimensions(); } The formal parameter type for add in Holder is Holdable. What does that require in any non-abstract class that implements Holder? It has a method add whose formal parameter type implements Holdable The definition of its add method has signature add(Holdable) It will not compile, since Holdable is an interface, not a class. It has an abstract add method None of the above