QUESTION 44Which declaration initializes a boolean variable?A.boolean h = 1;B.boolean k = 0;C.boolean m = null;D.boolean j = (1 < 5) ;Correct Answer: DSection: (none)
ExplanationExplanation/Reference:QUESTION 45Given:public class Basic{private static int letter;public static int getLetter();public static void Main(String[] args){System.out.println(getLetter());}}Why will the code not compile?BSection: (none)ExplanationExplanation/Reference:QUESTION 46Given:public class Circle{double radius;public double areapublic Circle(double r){radius = r;}public double getRadius(){return radius;}public void setRadius(double r){radius = r;}public double getArea(){return /* ??? */;}}class App
{public static void main(String[] args){Circle c1 = new Circle(17.4);c1.area = Math.PI * c1.getRadius() * c1.getRadius();}}This class is poorly encapsulated. You need to change the circle class to compute and return the areainstead.What three modifications are necessary to ensure that the class is being properly encapsulated?Correct Answer: ABCSection: (none)ExplanationExplanation/Reference:QUESTION 47Given a code fragment:StringBuilder sb = new StringBuilder();String h1 = "HelloWorld";sb.append("Hello").append("world");if (h1 == sb.toString()){System.out.println("They match");}if (h1.equals(sb.toString())){System.out.println("They really match");}What is the result?DSection: (none)ExplanationExplanation/Reference:QUESTION 48Given the following code:public class Simple{ /* Line 1 */
public float price; /* Line 2 */public static void main(String[] args){ /* Line 3 */Simple price = new Simple(); /* Line 4 */price = 4; /* Line 5 */} /* Line 6 */} /* Line 7 */What will make this code compile and run?A.Change line 2 to the following:Publicint priceB.Change line 4 to the following:int price = new simple ();C.Change line 4 to the following:Floatprice = new simple ();D.Change line 5 to the following:Price = 4f;E.Change line 5 to the following:price.price = 4;F.Change line 5 to the following:Price= (float) 4:G.Change line 5 to the following:Price= (Simple) 4;H.The code compiles and runs properly; no changes are necessaryCorrect Answer: ESection: (none)ExplanationExplanation/Reference:
You've reached the end of your free preview.
Want to read all 47 pages?
Fall '07
THAKUR
Correct Answer, Subroutine, Madrid Metro, Metropolitana di Napoli, A. Bob