Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Quiz; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Quizzes
1 / 4
CMSC 132 Quiz 1 Worksheet
The first Quiz of the course will be on Wednesday, Sept 7 during your lab (discussion) session. The following list provides more information about the quiz:
The following exercises cover the material to be included in Quiz #1. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with TAs and instructors during office hours.
public class Oven { protected String make;
public void turnOn() { System.out.println("Oven On"); } }
public class Microwave extends Oven { public double power;
public void turnOn() { System.out.println("Micro On"); }
public void turnOn(int thePower) { power = thePower; System.out.println("Micro On with " + power); } }
public static void main(String[] args) {
p.turnOn(10); VALID / INVALID
p.make = "GT"; VALID / INVALID
p.power = 200; VALID / INVALID
m.turnOn(20); VALID / INVALID
Microwave k = (Microwave)m; k.turnOn(200); VALID / INVALID
Microwave.make = "TU"; VALID/ INVALID
Oven.make = "TU"; VALID/ INVALID
Oven.turnOn(); VALID/ INVALID }
Oven v1 = new Microwave(); v1.turnOn();
Microwave v2 = new Oven(); v2.turnOn();
Output:
Output:
public interface Wireless { public double getRange(); }
public class Network { private String name; private int numComputers;
public Network(String n, int c) { name = n; numComputers = c; }
public Network(Network n) { name = new String(n.name); numComputers = n.numComputers; }
public String getName() { return name; }
public int getNumComputers() { return numComputers; } }