


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Problem 1 (General Questions)
int age = 17; double temp = 3.4; String m = “John” + age + “/” + temp;
String r; String s; // Step 1
r = s = “Happy”; // Step r = new String(s); // Step 3 r = null; // Step 4 r = new String(“John”); // Step 5
String k = null; System.out.println(k); System.out.println(k.length());
Problem 2
Problem 3
public static void main(String[] args) { int x; x = 2; String p; p = new String(“Test”); String t = null; // STOP HERE }
Stack Heap
2
a. In the MethodsExample class the printName method calls the validName method. Can all the methods of the class call each other? Does it make a difference whether the method is public or private? Does it make a difference the methods’ declaration order?
b. Indicate whether each of the following code segments are valid or invalid. Each code segment represents the body of the main method in the Driver class (where the //CODE SEGMENT comment appears).
i. MethodsExample e = new MethodsExample(); e.printAll("John", 20);
ii. MethodsExample e = new MethodsExample(); e.validName("John");
iii. MethodsExample e; e.printName("John");
iv. new MethodsExample().printAll("Mary", 16);
v. Revisit i. through iv. but assume all methods of the class MethodsExample are public.
vi. Revisit i. through iv. but assume all methods of the class MethodsExample are private.