Question: Please help!! Consider the following Java class definition: public class { private static int val; public int f(){ val =4; } This class definition is
Please help!!






Consider the following Java class definition: public class { private static int val; public int f(){ val =4; \} This class definition is illegal because instance method f attempts to access class variable val. Select one: True False Consider the following counter class: public class Counter \{ private static int count =0; public static void increment() \{ count++; public static int get() \{ return count; public static void reset() \{ count =0; \} What is the value of count after the execution of the following code fragment? Counter cnt1 = new Counter () ; Counter cnt2 = new Counter(); Counter cnt3 = new Counter( ) ; cnt1.increment(); cnt1.increment (); cnt1.increment (); cnt2.increment (); cnt3.increment(); cnt3.increment(); int count = cnt 2get(); a. 1 b. 4 c. 5 d. 3 e. 6 f. 0 g. 2 Consider the following class definition: public class Widget \{ private int value; public Widget (int val) value = val; \} public int get ()\{ return value; \} public void set(int n ) \{ \} value =n; In the following client code, is the object that w references mutable or immutable? Widget w= new Widget (5); a. it is neither mutable nor immutable b. it is immutable c. it is mutable d. it is both mutable and immutable A class maintains its class variables. No object (instance of the class) owns its class variables. All objects of the class share access to the class variables of the class. Select one: True False How can you distinguish an instance variable from a class variable in Java source code? a. A class variable is declared static, but an instance variable is not. b. An instance variable is declared public, but a class variable is not. c. A class variable is declared public, but an instance variable is not. d. An instance variable is declared static, but a class variable is not. e. You cannot distinguish a class variable from an instance variable because they are the same thing. Consider the following class definition: After the following client code executes: Widget w1= new Widget (5); Widget w2=w1; w2.set(1); what is the value of the following expression? w1.get() a. 0 b. 5 c. 1 d. w1 is no longer valid
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
