java.lang.Object.clone() method,
an object should implement ____Cloneable
____ interface.
public class SomethingIsWrong {
public interface anInterface {
void aMethod(int aValue) { System.out.println("Hi Mom"); }
}
public static void main(String[] args) {
StringBuffer[] stringBuffers = new StringBuffer[10];
for (int i = 0; i < stringBuffers.length; i++) {
stringBuffers[i].append("String Buffer at index " + i);
}
}
}
Please write your answer on the other side of page 1 --->
public class SomethingIsWrong {
public interface anInterface {
//interface should not implement any methods
void aMethod(int aValue);
}
public static void main(String[] args) {
StringBuffer[] stringBuffers = new StringBuffer[10];
for (int i = 0; i < stringBuffers.length; i++) {
//array elements should be created before they can be used
stringBuffers[i] = new StringBuffer();
stringBuffers[i].append("String Buffer at index " + i);
}
}
}
new Integer(1).equals(new Long(1))
try {
// do something
} finally {
// do something
}
catch (Exception e) {
// do something
}
i after the following code snippet
executes?
int i = 17; i >>= 2; i = i++%5;
false (of type
boolean). Although numerical values of
new Integer(1) and new Long(1) are the same,
but these quantities are of different types, and therefore are
considered not equal.catch statements
after a try statement as long as there is a
finally statement. 4
int i = 17; //i is 17 i >>= 2; //i is 17/4 which is 4 i = i++%5; //i is 4%5 which is 4
public interface TimeWatcher {
public void setTime(int h, int m, int s);
public void setDate(int mo, int d, int y);
}
java Adder 1 3 2 10
The program should display 16 and exit. In addition, your program should
catch and handle all exceptions that might arise because of a bad input.
Each type of exception should be handled independently, by printing an
appropriate error message which would specify what exactly was wrong
with the input. Hint: to convert a string representing an
integral number into an integer, you can use method
public static int java.lang.Integer.parseInt(String s)
throws NumberFormatException
public class Adder {
public static void main(String[] args) {
try {
int sum = Integer.parseInt(args[0]);
for (int i = 1; i < args.length; i++) {
sum += Integer.parseInt(args[i]);
}
System.out.println("The sum is " + sum);
} catch (NumberFormatException ex) {
System.out.println("Please enter only integral arguments.");
} catch (ArrayIndexOutOfBoundsException ex) {
System.out.println("Please enter one or more integral arguments.");
}
}
}