0
Alien head

programming languages Online Quiz - 179

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

Given: 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.printIn("x = " + ++x); } } } What is the result?

  1. x = 42

  2. x = 43

  3. x = 44

  4. Compilation fails.

  5. The code runs with no output


Correct Option: D

package testswitch; public class TestSwitch5 { public static void main(String[] args) { char a = 'a'; switch (a) { default: System.out.println("I am in default"); break; case 'a': System.out.println("I am in a"); break; } } }

  1. I am in a

  2. I am in default

  3. Exception

  4. Compiler Error


Correct Option: A

package testswitch; public class TestSwitch4 { public static void main(String[] args) { int x = 2; switch (x) { default: System.out.println("Default"); case 3: System.out.println("I am in 3"); case 1: System.out.println("I am in 1"); } } }

  1. Default I am in 3 I am in 1

  2. Default

  3. No output

  4. Exception


Correct Option: A

package testswitch; public class TestSwitch3 { public static void main(String[] args) { long p = 10; final long q = 100; switch (p) { case q: System.out.println("in q"); break; case 10: System.out.println("in 10"); break; default: System.out.println("default"); } } }

  1. in 10 Default

  2. Compiler error

  3. in 10

  4. Exception


Correct Option: B

package testswitch; public class TestSwitch1 { public static void main(String[] args) { int m=100; switch(100) { case m: System.out.println("in m"); default :System.out.println("default"); } } }

  1. in m Default

  2. Compiler Error

  3. in m

  4. default


Correct Option: B

package testswitch; public class TestSwitch { public static void main(String[] args) { int x = 2; switch (x) { default: System.out.println("Default"); break; case 3: System.out.println("I am in 3"); break; case 2: System.out.println("I am in 2"); break; } } }

  1. I am in 2

  2. Default I am in 2

  3. Default

  4. Compiler Error


Correct Option: A

C was given along with which operating system?

  1. DOS

  2. unix

  3. Solaris

  4. Both 1 and 2


Correct Option: B

#include int factorial(int n) { (n == 0)? return 1 : return n* factorial(n-1); } int main() { printf("%d",factorial(3)); }

  1. 6

  2. Errror

  3. 1

  4. No output


Correct Option: B

#include int main() { int main=7; printf("%d",main); }

  1. 777777.........

  2. Compilation Error

  3. 7

  4. None of the above


Correct Option: C

#include int main() { int i=0; for(;i--;); printf("%d",i); }

  1. 0

  2. 1

  3. Infinite loop

  4. -1


Correct Option: D

#include int main() { char s1[]="Dennis"; char s2[]="Dennis"; if(s1 == s2) printf(" The man behind C"); else printf(" Experience the legacy of C"); }

  1. The man behind C

  2. Experience the legacy of C

  3. Error : == operator cannot be applied to reference data types

  4. boolean cannot be converted to int


Correct Option: B

#include int main() { float dennis; switch(dennis) { default: printf("Let me work"); case 1: printf("This is case 1"); case 2: printf("This is case 2"); break; } }

  1. Let me work

  2. Let me workThis is case 1This is case 2

  3. Compilation Error

  4. Run Time Error


Correct Option: C

#include int main() { int i; if(i % 2) printf("I is Odd"), printf("I is Even"); }

  1. Error : Semicolon Missing

  2. Error: Misplaced Else

  3. I is odd

  4. I is odd I is Even

  5. No Output


Correct Option: D

#include int main() { printf("%d %f",6/4,6/4); }

  1. 1 1.000000

  2. 1 1.500000

  3. 0 1.000000

  4. 1 0.000000


Correct Option: D

#include int main () { ;;;;;; " Please Execute Me " ;;;;; // Line 6 printf(" Executing... ") // Line 7 ;;;;;; "Executed" ;;;;;;; // Line 8 }

  1. Executing...

  2. Please Execute Me Executing... Executed

  3. Error at line 6

  4. Error Semicolon missing


Correct Option: A

#include<stdio.h> int main() { int p[]={1,2,3}; printf("%d %d",p,(&p)+1); } If address of p is -123456 and int occupies 4 bytes then what would be the output?

  1. Compile Time Error

  2. -123456, -123460

  3. -123456, -123444

  4. -123456, -123452

  5. None of the above


Correct Option: C

package exceptions; public class TestException1 { static double testException(int x, int y) { return (x/y); } public static void main(String[] args) { try { double p = testException(10,0); System.out.println("p = "+p); System.out.println("Division done"); } catch(Exception e) { System.out.println("Exception happened "+e.getMessage()); } finally { System.out.println("In finally"); } } }

  1. Exception happened / by zero In finally

  2. Exception happened / by zero

  3. In finally

  4. Compiler Error


Correct Option: A

package exceptions; public class TestException3 { static double testException(int x, int y) { return (x/y); } public static void main(String[] args) { try { double p = testException(10,0); System.out.println("p = "+p); } catch(Exception e) { System.out.println("Exception happened "+e.getMessage()); System.exit(0); } finally { System.out.println("In finally"); } } }

  1. Compiler Error

  2. Exception happened / by zero

  3. Exception happened / by zero In finally

  4. In finally


Correct Option: B

package exceptions; public class TestException2 { static double testException(int x, int y) { return (x/y); } public static void main(String[] args) { try { double p = testException(10,5); System.out.println("p = "+p); } catch(Exception e) { System.out.println("Exception happened "+e.getMessage()); return; } finally { System.out.println("In finally"); } } }

  1. p = 2.0

  2. Compiler Error

  3. Exception

  4. p = 2.0 In finally


Correct Option: D

package exceptions; public class TestException5 { static String trimString(String x) { return x.trim(); } public static void main(String[] args) { try { String s = trimString(null); System.out.println("s = "+s); } catch(Exception e) { System.out.println(" Exception "); } catch(NullPointerException ne) { System.out.println("Null Pointer Exception "); } } }

  1. s = tcs Exception

  2. s = tcs Null Pointer Exception

  3. Exception

  4. Compiler Error


Correct Option: D
+ View questions