MCQOPTIONS
Saved Bookmarks
This section includes 5 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is the output of this program?import java.io.*; public class streams_Example { public static void main(String[] args) { try { FileOutputStream FOS = new FileOutputStream("serial"); ObjectOutputStream OOS = new ObjectOutputStream(FOS); OOS.writeDouble(1.5); OOS.flush(); OOS.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { float p; FileInputStream FIS = new FileInputStream("serial"); ObjectInputStream OIS = new ObjectInputStream(FIS); p = OIS.readInt(); OIS.close(); System.out.println(p); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } |
| A. | 1.07 |
| B. | 1.07321754E9 |
| C. | 1.07321 |
| D. | 2.07321754E9 |
| E. | None of these |
| Answer» C. 1.07321 | |
| 2. |
What is the output of this program?import java.io.*; public class serialization_Example { public static void main(String[] args) { try { Newclass obj1 = new Newclass("InterviewMania", -10, 3.2e20); FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(obj1); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { int p; FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); p = ois.readInt(); ois.close(); System.out.println(p); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } class Newclass implements Serializable { String str; int k; double q; Newclass(String str, int k, double q) { this.q = q; this.k = k; this.str = str; } } |
| A. | Compilation error |
| B. | Runtime error |
| C. | InterviewMania |
| D. | deserialization |
| E. | None of these |
| Answer» E. None of these | |
| 3. |
What is the output of this program?import java.io.*; public class serialization_Example { public static void main(String[] args) { try { Newclass obj1 = new Newclass("InterviewMania", -10, 3.2e20); FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(obj1); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { Newclass obj2; FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); obj2 = (Newclass)ois.readObject(); ois.close(); System.out.println(obj2); } catch (Exception e) { System.out.print("deserialization" + e); System.exit(0); } } } class Newclass implements Serializable { String str; int k; double p; Newclass (String str, int k, double p) { this.p = p; this.k = k; this.str = str; } } |
| A. | Newclass@776ec8df |
| B. | InterviewMania |
| C. | Interview |
| D. | Mania |
| E. | None of these |
| Answer» B. InterviewMania | |
| 4. |
What will be printed to the output and written to the file, in the below program?import java.io.*; public class FileOutputStreamExample{ public static void main(String args[]) { try { FileOutputStream FOS = new FileOutputStream("D: InterviewMania.txt"); String str="Welcome to the Interview Mania."; byte q[]=str.getBytes();//converting string into byte array FOS.write(q); FOS.close(); System.out.println("Success"); } catch(Exception e){System.out.println(e);} } } |
| A. | Only "Welcome to the Interview Mania" |
| B. | Compile time error |
| C. | "Success" to the output and "Welcome to the xInterview Mania" |
| D. | Runtime error |
| E. | None of these |
| Answer» D. Runtime error | |
| 5. |
What will be printed to the output and written to the file, in the below program? |
| A. | Only "Welcome to the Interview Mania" |
| B. | Compile time error |
| C. | "Success" to the output and "Welcome to the xInterview Mania" |
| D. | Runtime error |
| E. | None of these |
| Answer» D. Runtime error | |