0

programming languages Online Quiz - 134

Description: programming languages Online Quiz - 134
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

When assigning a value to a reference variable, type doesn't matter.

  1. True

  2. False


Correct Option: B
  1. IllegalStateException

  2. NumberFormatException

  3. IllegalArgumentException

  4. ClassCastException


Correct Option: A,B,C

class Hello{} class Hai extends Hello{} class Me{ static int x=7; static String s=null; public static void getWeight(Hello m){ int y=0/x; System.out.print(s+""); } public static void main(String [] args){ Hello [] ha={new Hello(),new Hai()}; for(Object o:ha) getWeight((Hello)o); } } When i run as--- java Me.java

  1. NoClassDefFoundError

  2. ClassCastException

  3. ArthmeticException

  4. IllegalArgumentException


Correct Option: A

What is the result? class Circus { public static void main(String[] args) { int x = 9; int y = 6; for(int z = 0; z < 6; z++, y--) { if(x > 2) x--; label: if(x > 5) { System.out.print(x + " "); --x; continue label; } x--; } } }

  1. 8

  2. 8 7

  3. An exception is thrown at runtime.

  4. Compilation fails.


Correct Option: D

class MyThread extends Thread { MyThread() { System.out.print(" MyThread"); } public void run() { System.out.print(" bar"); } public void run(String s) { System.out.print(" baz"); } } public class TestThreads { public static void main (String [] args) { Thread t = new MyThread() { public void run() { System.out.print(" foo"); } }; t.start(); } } What is the result?

  1. MyThread foo

  2. MyThread bar

  3. foo bar

  4. foo bar baz


Correct Option: A

public static synchronized void main(String[] args) throws InterruptedException { Thread t = new Thread(); t.start(); System.out.print("X"); t.wait(10000); System.out.print("Y"); } What is the result of this code?

  1. It prints X and never exits.

  2. The code does not compile.

  3. It prints XY with a 10-second delay between X and Y.

  4. An exception is thrown at runtime.


Correct Option: D
  1. notify();

  2. wait(long msecs);

  3. interrupt();

  4. synchronized();


Correct Option: A,B

import static java.lang.System.*; class _ { static public void main(String... _A_V) { String $ = ""; for(int x=0; ++x < _A_V.length; ) $ += _A_V[x]; out.println($); } } And the command line: java _ - A .

  1. -A.

  2. An exception is thrown at runtime.

  3. -A

  4. A


Correct Option: D
  1. class Dog { } 2. class Beagle extends Dog { } 3. 4. class Kennel { 5. public static void main(String [] arfs) { 6. Beagle b1 = new Beagle(); 7. Dog dog1 = new Dog(); 8. Dog dog2 = b1; 9. // insert code here 10. } 11. } Which, inserted at line 9, will compile? (Choose all that apply.)
  1. Beagle b2 = (Beagle) dog1;

  2. Runtime Exception

  3. Beagle b4 = dog2;

  4. None of the above statements will compile


Correct Option: A

class Scoop { static int thrower() throws Exception { return 42; } public static void main(String [] args) { try { int x = thrower(); } catch (Exception e) { x++; } finally { System.out.println("x = " + ++x); } } } What is the result?

  1. x = 42

  2. x = 43

  3. x = 44

  4. Compilation fails.


Correct Option: D

What will be the output of the following program?

  1. 0

  2. 1

  3. Compilation Error

  4. Runtime Exception


Correct Option: C

What is the output of the program?

  1. 0

  2. 1

  3. Compilation Error

  4. Runtime Exception


Correct Option: C

Which of these statements are true?

  1. There can be any number of var-arg parameters in a method

  2. Only one var-arg parameter is allowed and it must be declared as last parameter in method definition.

  3. Only one var-arg parameter is allowed and it must be declared as first parameter in method definition.

  4. None of the above


Correct Option: B
- Hide questions