cancel
Showing results for 
Search instead for 
Did you mean: 

File Input Output in java

Former Member
0 Kudos

hello! I m a beginner in java..kindly help me to solve this question.

wat'll happen when u compile and run this code?

import java.io.*;

class Base{

public void amethod()throws FileNotFounfexception{}

}

public class ExcepDemo extends Base{

public static void main(String argv[]){

ExcepDemo e=new ExcepDemo();

}

public void amethod(){}

protected ExcepDemo(){

try{

DataInputStream din = new DataInputStream( System.in);

System.out.println("Pausing");

din.readByte();

System.out.println("Continuing");

this.amethod();

}catch(IOEception ioe){}

}

}

Options----

1. Compile time error caused by protected costructor

2. Compile time error caused by amethod not declaring Exception

3. Runtime error caused by amethod not declaring Exception

4. Compile and run with output of "Pausing" and "Continuing" after a key is hit.

Accepted Solutions (1)

Accepted Solutions (1)

Torsten_
Advisor
Advisor
0 Kudos

Hello,

you've some syntax errors in your code like

<b>FileNotFounfexception == FileNotFoundException</b> or

<b>IOEception = IOException</b>

Here is the runable code:

import java.io.DataInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

class Base {
	public void amethod() throws FileNotFoundException {
	}
}

public class ExcepDemo extends Base {
	public static void main(String argv[]) {
		ExcepDemo e = new ExcepDemo();
	}

	public void amethod() {
	}

	protected ExcepDemo() {

		try {
			DataInputStream din = new DataInputStream(System.in);
			System.out.println("Pausing");
			din.readByte();
			System.out.println("Continuing");
			this.amethod();
		} catch (IOException ioe) {
		}
	}
}

When you run this class in a command window the code line

din.readByte();

will wait until the user hit the Enter Key (CR/LF)

Hope this help

Torsten

Answers (0)