Question: Please help! All instances of a class share the same class variables. Select one: True False Java String objects are immutable. Select one: True False
Please help!







All instances of a class share the same class variables. Select one: True False Java String objects are immutable. Select one: True False Consider the following Java class definition: public class x{ private int val; public static int f(){ val =4; \} This class definition is illegal because class method f attempts to access instance variable val. Select one: True False 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; After the following client code executes: Widget w1= new Widget(5); Widget w2= new Widget (20);// A. w2=w1 what happens to the Widget object created at the line labeled A ? a. it results in a memory leak unless the programmer adds the code to deallocate the object b. nothing c. it is eligible for garbage collection How can you distinguish an instance method from a class method in Java source code? a. A class method is declared public, but an instance method is not. b. An instance method is declared public, but a class method is not. c. An instance method is declared static, but a class method is not. d. A class method is declared static, but an instance method is not. e. You cannot distinguish a class method from an instance method because they are the same thing. The more private fields and private methods a class contains, the more difficult it is for clients to use the class. Select one: True False Consider the following counter class: public class Counter \{ private int count =0; public Counter() count =0; \} public void increment() \{ count++; public int get() \{ return count; public 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 =cnt2get(); a. 5 b. 1 c. 3 d. 6 e. 4 f. 0 g. 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
