Tag: programming languages

Questions Related to programming languages

For Object A to access method of object B, and the method has no modifier, Object A must be an instance of class which is ...

  1. Same package as B

  2. In different package

  3. mark a default acess modifier to the class

  4. None


Correct Option: A

Each source file should have a public class in it ?

  1. True

  2. False


Correct Option: B

Methods which are marked as Protected can be accessed only by classes with in the same package?

  1. True

  2. False


Correct Option: B

Can abstract classes have non - abstract methods?

  1. True

  2. False


Correct Option: A

In a switch construct the execution will continue till

  1. a match case is found

  2. a match case is found and break is encountered

  3. will continue till default

  4. none


Correct Option: B

Using a break in a for loop , causes the loop to break out of the current iteration and jump to the next iteration of the loop...

  1. True

  2. False


Correct Option: A

class C{ int i; public static void main (String[] args) { int i; //1 private int a = 1; //2 protected int b = 1; //3 public int c = 1; //4 System.out.println(a+b+c); //5 }}

  1. Compile error at 2,3,4,5

  2. Compile error at 1,2,3,4,5

  3. prints 3

  4. none of the above


Correct Option: A

class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); }}} What is the result of attempting to compile and run the program?

  1. Prints one, two , three

  2. prints one

  3. compile time error

  4. Run time Exception


Correct Option: A