Essay on The Republic Day | Republic Day Essay in English
[ Festival Ganesh Chaturthi Essay in English for Students and Children ] [ Essay on my favourite freedom fighter ] ⚔️ [ दुर्गा पूजा पर निबंध (Durga Puja Hindi Essay) ]
[Essay On 75th Independence Day Of India] [Azadi Ka Amrit Mahotsav Essay in English]

What will be the output of the program?


			  		

Loading

Practice Exceptions –

What will be the output of the program?

public class X {      
public static void main(String [] args) {
try {
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */ {
System.out.print("B");
}
catch (Exception ex1) {
System.out.print("C");
}
finally {
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod() {
throw new RuntimeException();
}
}

 

import java.io.*; 
public class

Loading

Practice Exceptions –

import java.io.*; 
public class MyProgram {
public static void main(String args[]) {
FileOutputStream out = null;
try {
out = new FileOutputStream("test.txt");
out.write(122);
}
catch(IOException io) {
System.out.println("IO Error.");
}
finally {
out.close();
}
}
}

and given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?

What will be the output of the program?


			  		

Loading

Practice Exceptions –

What will be the output of the program?

public class X  {       
public static void main(String [] args) {
try {
badMethod(); /* Line 7 */
System.out.print("A");
}
catch (Exception ex) /* Line 10 */ {
System.out.print("B"); /* Line 12 */
}
finally /* Line 14 */ {
System.out.print("C"); /* Line 16 */
}
System.out.print("D"); /* Line 18 */
}
public static void badMethod() {
throw new RuntimeException();
}
}

 

What will be the output of the program?


			  		

Loading

Practice Exceptions –

What will be the output of the program?

public class Test {       
public static void aMethod() throws Exception {
try /* Line 5 */ {
throw new Exception(); /* Line 7 */
}
finally /* Line 9 */ {
System.out.print("finally "); /* Line 11 */
}
}
public static void main(String args[]) {
try {
aMethod();
}
catch (Exception e) /* Line 20 */ {
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}

 

What will be the output of the program?


			  		

Loading

Practice Exceptions –

What will be the output of the program?

public class RTExcept  {     
public static void throwit () {
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args) {
try {
System.out.print("hello ");
throwit();
}
catch (Exception re ) {
System.out.print("caught ");
}
finally {
System.out.print("finally ");
}
System.out.println("after ");
}
}