0
Alien head

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

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

What is the output of the program?

  1. 0

  2. 1

  3. Compilation Error

  4. Runtime Exception


Correct Option: C

What will be the output of the following program?

  1. 0

  2. 1

  3. Compilation Error

  4. Runtime Exception


Correct Option: C

class Fizz { int x = 5; public static void main(String[] args) { final Fizz f1 = new Fizz(); Fizz f2 = new Fizz(); Fizz f3 = FizzSwitch(f1,f2); System.out.println((f1 == f3) + " " + (f1.x == f3.x)); } static Fizz FizzSwitch(Fizz x, Fizz y) { final Fizz z = x; z.x = 6; return z; } } What is the result?

  1. true false

  2. true true

  3. false true

  4. false false


Correct Option: B

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
  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
  1. class X { void do1() { } } 2. class Y extends X { void do2() { } } 3. 4. class Chrome { 5. public static void main(String [] args) { 6. X x1 = new X(); 7. X x2 = new Y(); 8. Y y1 = new Y(); 9. // insert code here 10. } 11. } Which, inserted at line 9, will compile? (Choose all that apply.)
  1. (Y)x2.do2();

  2. x2.do2();

  3. ((Y)x2).do2();

  4. None of the above statements will compile


Correct Option: C

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

public abstract class AbstractTest { public int getNum() { return 45; } public abstract class Bar { public int getNum() { return 38; } } public static void main(String[] args) { AbstractTest t = new AbstractTest() { public int getNum() { return 22; } }; AbstractTest.Bar f = t.new Bar() { public int getNum() { return 57; } }; System.out.println(f.getNum() + " " + t.getNum()); } } What is the result?

  1. An exception occurs at runtime.

  2. Compilation fails.

  3. 57 22

  4. 45 57


Correct Option: D

Which method names follow the JavaBeans standard? (Choose all that apply.)

  1. getCust

  2. isColorado

  3. addSize

  4. putDimensions


Correct Option: A,B

Which are methods of the Object class? (Choose all that apply.)

  1. notify();

  2. wait(long msecs);

  3. interrupt();

  4. synchronized();


Correct Option: A,B

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

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

class Eggs { int doX(Long x, Long y) { return 1; } int doX(long... x) { return 2; } int doX(Integer x, Integer y) { return 3; } int doX(Number n, Number m) { return 4; } public static void main(String[] args) { new Eggs().go(); } void go() { short s = 7; System.out.print(doX(s,s) + " "); System.out.println(doX(7,7)); } } What is the result?

  1. 3 3

  2. 4 1

  3. 4 3

  4. 2 1


Correct Option: C

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 Emu { static String s = "-"; public static void main(String[] args) { try { throw new Exception(); } catch (Exception e) { try { try { throw new Exception(); } catch (Exception ex) { s += "ic "; } throw new Exception(); } catch (Exception x) { s += "mc "; } finally { s += "mf "; } } finally { s += "of "; } System.out.println(s); } }

  1. -ic mc of mf

  2. Compilation fails.

  3. -ic mc mf of

  4. -ic mf of


Correct Option: 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

Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM.

  1. IllegalStateException

  2. NumberFormatException

  3. IllegalArgumentException

  4. ClassCastException


Correct Option: A,B,C

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

  1. True

  2. False


Correct Option: B

Expressions are evaluated from right to left by default.

  1. True

  2. False


Correct Option: B
+ View questions