// method: fileRead(String s) // purpose: opens up file s and reads (output to t
ID: 3619070 • Letter: #
Question
// method: fileRead(String s)
// purpose: opens up file s and reads (output to the screen)– one int per line
//
void fileRead(String s) { System.out.println(“fileReadreached”); }
// method: fileWrite(String s, int[] a)
// purpose: opens up file s and writes a to it – one int perline
//
void fileWrite(String s) { System.out.println(“fileWritereached”); }
}
You are to inherit from StdOpts and override each method so theyactually work. In addition, overload fileRead so that it can take aFile object as an argument instead of a string. Call your new classRealOpts.
Explanation / Answer
//Here is RealOpts.java, hope thiswill help you. import java.io.*; class StdOps { // method: fileRead(String s) // purpose: opens up file s and reads (output to the screen)– one int per line // void fileRead(String s) { System.out.println("fileRead reached");} // method: fileWrite(String s, int[] a) // purpose: opens up file s and writes a to it – one int perline // void fileWrite(String s) { System.out.println("fileWrite reached");} } class RealOpts extends StdOps { /* Over Ride */ void fileRead(String s) { System.out.println("RealOpts fileReadreached"); } /* Over Load */ void fileRead(FileReader f) { System.out.println("RealOptsFileReader fileRead reached"); } /* Over Ride */ void fileWrite(String s) { System.out.println("RealOpts fileWritereached"); } public static void main(String args[]) { RealOpts r=new RealOpts(); FileReader f=null; r.fileRead("Hi"); r.fileRead(f); } } /* Output RealOpts fileRead reached RealOpts FileReader fileRead reached */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.