Java Reference
In-Depth Information
Answers
1. b. Answer (a.) is a good idea, though variable name conflicts can be a source of
subtle errors in your Java programs.
2. b. Customarily, instance variables are declared right after the class declaration and
before any methods. It's necessary only that they be outside all methods.
3. a. The quotation marks are not included in the argument when it is passed to the
program.
Certification Practice
The following question is the kind of thing you could expect to be asked on a Java pro-
gramming certification test. Answer it without looking at today's material or using the
Java compiler to test the code.
Given:
public class BigValue {
float result;
public BigValue(int a, int b) {
result = calculateResult(a, b);
}
float calculateResult(int a, int b) {
return (a * 10) + (b * 2);
}
5
public static void main(String[] arguments) {
BiggerValue bgr = new BiggerValue(2, 3, 4);
System.out.println(“The result is “ + bgr.result);
}
}
class BiggerValue extends BigValue {
BiggerValue(int a, int b, int c) {
super(a, b);
result = calculateResult(a, b, c);
}
// answer goes here
return (c * 3) * result;
}
}
Search WWH ::




Custom Search