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 "); } } }
s = tcs Exception
s = tcs Null Pointer Exception
Exception
Compiler Error
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"); } } }
p = 2.0
p = 2.0 In finally
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"); } } }
Exception happened / by zero
Exception happened / by zero In finally
In finally
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"); } } }
#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?
Compile Time Error
-123456, -123460
-123456, -123444
-123456, -123452
None of the above
#include int main () { ;;;;;; " Please Execute Me " ;;;;; // Line 6 printf(" Executing... ") // Line 7 ;;;;;; "Executed" ;;;;;;; // Line 8 }
Executing...
Please Execute Me Executing... Executed
Error at line 6
Error Semicolon missing
#include int main() { printf("%d %f",6/4,6/4); }
1 1.000000
1 1.500000
0 1.000000
1 0.000000
#include int main() { int i; if(i % 2) printf("I is Odd"), printf("I is Even"); }
Error : Semicolon Missing
Error: Misplaced Else
I is odd
I is odd I is Even
No Output
#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; } }
Let me work
Let me workThis is case 1This is case 2
Compilation Error
Run Time Error
#include int main() { char s1[]="Dennis"; char s2[]="Dennis"; if(s1 == s2) printf(" The man behind C"); else printf(" Experience the legacy of C"); }
The man behind C
Experience the legacy of C
Error : == operator cannot be applied to reference data types
boolean cannot be converted to int