




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
Main points of this past exam are: Legal Java, Static Void, Public Static, New Boolean, Void Crazy, Without Errors, Return Value, Balance Less, Syntactically Valid, Valid Code
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





You have 50 minutes to finish this test. Your exam should contain 6 problems (numbered 0-5) on 8 total pages. This is an open-book test. You may consult any books, notes, or other paper-based inanimate objects available to you. Read the problems carefully. If you find it hard to understand a problem, please ask a question. Partial credit will be awarded where we can, so do try to answer each question. Please write your answers in the spaces provided in the test; if you need to use the back of a page make sure to clearly tell us so on the front of the page.
Good Luck!
int [] myArray = {1, 2, 3, 4, 5}; System. out .println(myArray[4]); myArray = new int [4]; System. out .println(myArray[3]);
below. There are no compile-time or run-time errors in this program.
For each example of code, respond whether or not it will compile. If it compiles, please respond whether or not it will run without errors. If it runs without errors and has a return value, please write the return value.
interface X { int method(); } class Y implements X { int method(){ return 0; } private double method(String arg){ return 12.20; } } class Z extends Y{ double method(String arg){ return 3.14; } } public class testXYZ{ public static void main(String[] args) {
Fill in the blanks below with legal Java to produce the output indicated in each comment. If it is impossible
public class Parent { public void feed(Parent p){ System. out .println("Parent feed Parent"); } public void feed(Child c){ System. out .println("Parent feed Child"); } } public class Child extends Parent { public void feed(Parent p){ System. out .println("Child feed Parent"); } public void feed(Child c){ System. out .println("Child feed Child"); } public static void main(String[] args) { Parent p = new Child();
// Child feed Child
// Child feed Parent
// Parent feed Child
// Parent feed Parent
p = new Parent();
// Child feed Child
// Child feed Parent
// Parent feed Child
// Parent feed Parent
} }
b) Modify the removePoorParents() method below to fix the bug you demonstrated in part a).
Please fill out the names of people around you
Kaushik 11- 2
David 2 - 5
George 6 - 9