8.6 |
Given the following class, which of these static initializer blocks can be inserted after the comment? public class MyClass { private static int count = 5; final static int STEP = 10; boolean alive; // INSERT STATIC INITIALIZER BLOCK HERE } Select the three correct answers.
|
8.7 |
What will be the result of attempting to compile and run the following code? public class MyClass { public static void main(String[] args) { MyClass obj = new MyClass(l); } static int i = 5; static int l; int j = 7; int k; public MyClass(int m) { System.out.println(i + ", " + j + ", " + k + ", " + l + ", " + m); } { j = 70; l = 20; } // Instance Initializer Block static { i = 50; } // Static Initializer Block } Select the one correct answer.
|
8.8 |
Given the following class, which instance initializer block inserted at the indicated location will allow the class to compile without errors? public class MyClass { static int gap = 10; double length; final boolean active; // INSERT CODE HERE } Select the one correct answer.
|
8.9 |
What will be the result of attempting to compile and run the following program? public class Initialization { private static String msg(String msg) { System.out.println(msg); return msg; } public Initialization() { m = msg("1"); } { m = msg("2"); } String m = msg("3"); public static void main(String[] args) { Object obj = new Initialization(); } } Select the one correct answer.
|
8.10 |
What will be the result of attempting to compile and run the following program? public class Initialization { private static String msg(String msg) { System.out.println(msg); return msg; } static String m = msg("1"); { m = msg("2"); } static { m = msg("3"); } public static void main(String[] args) { Object obj = new Initialization(); } } Select the one correct answer.
|
8.11 |
Which of the labeled lines in the following code can be uncommented by removing the // characters and still allow the code to compile correctly? class GeomInit { // int width = 14; /* Line A */ { // area = width * height; /* Line B */ } int width = 37; { // height = 11; /* Line C */ } int height, area; // area = width * height; /* Line D */ { // int width = 15; /* Line E */ area = 100; } }; Select the two correct answers.
|