Which declaration initializes a boolean variable A boolean h 1 B boolean k 0 C

Which declaration initializes a boolean variable a

This preview shows page 22 - 26 out of 47 pages.

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: D Section: (none)
Image of page 22
Explanation Explanation/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? B Section: (none) Explanation Explanation/Reference: QUESTION 46 Given: public class Circle { double radius; public double area public Circle(double r) { radius = r; } public double getRadius() { return radius; } public void setRadius(double r) { radius = r; } public double getArea() { return /* ??? */; } } class App
Image of page 23
{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: ABC Section: (none) Explanation Explanation/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? D Section: (none) Explanation Explanation/Reference: QUESTION 48Given the following code:public class Simple{ /* Line 1 */
Image of page 24
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: E Section: (none) Explanation Explanation/Reference:
Image of page 25
Image of page 26

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

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture