Download presentation
Presentation is loading. Please wait.
1
m/c 6-10 t/f 6-10 AP free style s/a 7.6-7.7
Chapter 7 answers m/c 6-10 t/f 6-10 AP free style s/a
2
Multiple choice 6 Give classes A and B what will print for
Class A{void foo(){ prints “A’s foo”} Class B extends A {void foo() {prints “B’s foo”} A aRef = new B(); aRef.foo(); b
3
Given Object obj = new String(“hello”); which will NOT cause a compile error?
obj.toUpperCase(); obj.substring(0,5); obj.equals(“hi”); obj.compareTo(“hi”); All of them will cause a compile error c
4
8. Given void doSomething(Object param) which is NOT a valid call?
doSomething(“Java”); doSomething(new String(“Java”); doSomething(14); doSomething(new Integer(14)); All are valid calls C according to the book but they are wrong because of autoboxing which changes the int in c to an Integer object
5
9 b
6
10 e
7
True/False A class can be both a superclass and a subclass
All classes are derived from the Object class An abstract class cannot be instantiated A polymorphic reference variable can point to different types of objects at different times Polymorphism may occur with inheritance but not with interfaces F
8
AP Multiple Choice 6. A In warmup file
9
See BlueJ for short answer 7.6 traffic light and 7.7 rubber circle
10
AP-Style Free Response Solution
public class Perishable extends InventoryItem { private Date expiration; private static final double DISCOUNT = 0.01; public Perishable (Date entry, double price, Date expirationDate) super (entry, price); expiration = expirationDate; } public double getPrice() if (expiration.compareTo(getEntryDate()) < 0) return getBasePrice() * DISCOUNT; else return getBasePrice(); b. public ArrayList<InventoryItem> getItems (double loPrice, double hiPrice) ArrayList<InventoryItem> list = new ArrayList<InventoryItem>(); for (InventoryItem ii : items) if ((ii.getPrice() >= loPrice) && (ii.getPrice() <= hiPrice)) list.add(ii); return list;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.