Tag: programming languages

Questions Related to programming languages

  1. public int a []

  2. static int [] a

  3. private int a [3]

  4. public final int [] a

  5. public [] int a

  6. private int [3] a []


Correct Option: A,B,D
  1. public class Thing {}

  2. public class Thing { public Thing(void) { } }

  3. public class Thing { public Thing() { } }

  4. public class Thing { public Thing(String s) { } }


Correct Option: A,C
  1. The default constructor initializes method variables.

  2. The default constructor has the same access as its class.

  3. The default constructor invoked the no-arg constructor of the superclass.

  4. If a class lacks a no-arg constructor, the compiler always creates a default constructor.

  5. The compiler creates a default constructor only when there are no other constructors for the class.


Correct Option: B,C,E
  1. int[] scores = {3, 5, 7};

  2. int [][] scores = {2,7,6}, {9,3,45};

  3. String cats[] = {“Fluffy”, “Spot”, “Zeus”};

  4. boolean results[] = new boolean [3] {true, false, true};


Correct Option: B,D
  1. Explicitly setting myA to null marks that instance to be eligible for garbage collection

  2. Private instances of A become eligible for garbage collection when instances of Alpha become eligible for garbage collection.

  3. Any call on tryIt() causes the private instance of A to be marked for garbage collection.

  4. There are no instanced of A that will become eligible for garbage collection.


Correct Option: A,B
  1. Implementation details of the class are hidden.

  2. Access modifiers can be omitted on class data members.

  3. Internal operation of the class can be modified without impacting clients of that class.

  4. Code that uses the encapsulation class can access data members directly.

  5. Performance of class methods is improved.


Correct Option: A,C

find the output:: public class HelloThread extends Thread { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new HelloThread()).start(); } }

  1. compiler error

  2. Hello from a thread!

  3. runtime error

  4. none of these


Correct Option: B
  1. millisecond

  2. nanosecond

  3. second

  4. depends on OS


Correct Option: D
  1. Extend the java.lang.Throwable class

  2. Extend the java.lang.Thread class

  3. Extend the java.lang.Runnable

  4. Implement the Runnable interface


Correct Option: B,D