Tag: programming languages

Questions Related to programming languages

  1. 0 false 0

  2. 0 true 0

  3. 0 0 0

  4. Compile error - static variable must be initialized before use.


Correct Option: A
Explanation:

To solve this question, the user needs to know about Java classes, instance variables, static variables, and method invocation.

The given program has two classes: A and Test. The A class defines three instance variables: k (of type int), istrue (of type boolean), and a static variable p (of type int). Class A also defines a method named printValue() that prints the values of k, istrue, and p, in that order.

In the main() method of the Test class, an object of class A is created and its printValue() method is called.

Since int and boolean instance variables are initialized to their default values of 0 and false respectively, and the static variable p is also initialized to 0, the output of the program will be:

A. 0 false 0

Option A is correct because the program will print the values of k (0), istrue (false), and p (0) in that order.

Option B is incorrect because istrue is initialized to false, not true.

Option C is incorrect because k and istrue are both non-static instance variables, and they will be initialized to their default values of 0 and false, respectively. The static variable p will also be initialized to 0.

Option D is incorrect because there is no compile error in the code.

The Answer is: A. 0 false 0

If we do ArrayList lst = new ArrayList(); What is the initial capacity of the ArrayList lst ?

  1. 8

  2. 10

  3. none

  4. 0


Correct Option: B
  1. Map m = Collection.synchronizeMap(hashMap);

  2. Map m = Collections.synchronizeMap(hashMap);

  3. Map m = hashMap.synchronizeMap();

  4. none


Correct Option: B