250+ TOP MCQs on Observable & Timer Class and Answers

Java MCQs on Observable & Timer class of Java Programming Language.

1. What is the use of Observable class?
a) It is used to create global subclasses
b) It is used to create classes that other part of the program can observe
c) It is used to create classes that can be accessed by other parts of program
d) It is used to create methods that can be accessed by other parts of program

Answer: b
Clarification: The Observable class is used to create subclasses that other part of program can observe.

2. Which of these methods is used to notify observer the change in observed object?
a) update()
b) notify()
c) check()
d) observed()

Answer: a
Clarification: None.

3. Which of these methods calls update() method?
a) notify()
b) observeObject()
c) updateObserver()
d) notifyObserver()

Answer: d
Clarification: notifyObserver() notifies all the observers of the invoking object that it has changed by calling update(). A null is passed as the second argument to update().

4. Which of these methods is called when observed object has changed?
a) setChanged()
b) update()
c) notifyObserver()
d) all of the mentioned

Answer: d
Clarification: None.

5. Which of these classes can schedule task for execution in future?
a) Thread
b) Timer
c) System
d) Observer

Answer: b
Clarification: Timer and TimerTask are the classes that support the ability to schedule tasks for execution at some future time.

6. Which of these interfaces is implemented by TimerTask class?
a) Runnable
b) Thread
c) Observer
d) ThreadCount

Answer: a
Clarification: None.

7. Which of these package provides the ability to read and write in Zip format?
a) java.lang
b) java.io
c) java.util.zip
d) java.util.zar

Answer: c
Clarification: None.

Global Education & Learning Series – Java Programming Language.

Advanced 250+ TOP MCQs on Java Beans and Answers

This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “Java Beans”.

1. Which of the following is not an Enterprise Beans type?
a) Doubleton
b) Singleton
c) Stateful
d) Stateless

Answer: a
Clarification: Stateful, Stateless and Singleton are session beans.

2. Which of the following is not true about Java beans?
a) Implements java.io.Serializable interface
b) Extends java.io.Serializable class
c) Provides no argument constructor
d) Provides setter and getter methods for its properties

Answer: b
Clarification: java.io.Serializable is not a class. Instead it is an interface. Hence it cannot be extended.

3. Which file separator should be used by MANIFEST file?
a) /
b)
c) –
d) //

Answer: a
Clarification: MANIFEST file uses classes using / file separator.

4. Which of the following is correct error when loading JAR file with duplicate name?
a) java.io.NullPointerException
b) java.lang.ClassNotFound
c) java.lang.ClassFormatError
d) java.lang.DuplicateClassError

Answer: c
Clarification: java.lang.ClassFormatError: Duplicate Name error is thrown when .class file in the JAR contains a class whose class name is different from the expected name.

5. Java Beans are extremely secured?
a) True
b) False

Answer: b
Clarification: JavaBeans do not add any security features to the Java platform.

6. Which of the following is not a feature of Beans?
a) Introspection
b) Events
c) Persistence
d) Serialization

Answer: d
Clarification: Serialization is not the feature of Java Beans. Introspection, Customization, Events, Properties and Persistence are the features.

7. What is the attribute of java bean to specify scope of bean to have single instance per Spring IOC?
a) prototype
b) singleton
c) request
d) session

Answer: b
Clarification: Singleton scope of bean specifies only one instance per spring IOC container. This is the default scope.

8. Which attribute is used to specify initialization method?
a) init
b) init-method
c) initialization
d) initialization-method

Answer: b
Clarification: init-method is used to specify the initialization method.

 <bean id = "helloWorld" class = "com.bean.HelloWorld" init-method = "init" />

9. Which attribute is used to specify destroy method?
a) destroy
b) destroy-method
c) destruction
d) destruction-method

Answer: b
Clarification: destroy-method is used to specify the destruction method.

 <bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld" destroy-method = "destroy" />

10. How to specify autowiring by name?
a) @Qualifier
b) @Type
c) @Constructor
d) @Name

Answer: a
Clarification: Different beans of the same class are identified by name.

  1. 	     @Qualifier("student1")
  2. 	     @Autowired
  3. 	     Student student1;

250+ TOP MCQs on Relational Operators and Boolean Logic Operators and Answers

Java MCQs on relational operators and boolean logic operators of Java Programming Language.

1. What is the output of relational operators?
a) Integer
b) Boolean
c) Characters
d) Double

Answer: b
Clarification: None.

2. Which of these is returned by “greater than”, “less than” and “equal to” operators?
a) Integers
b) Floating – point numbers
c) Boolean
d) None of the mentioned

Answer: c
Clarification: All relational operators return a boolean value ie. true and false.

3. Which of the following operators can operate on a boolean variable?

a) 3 & 2
b) 1 & 4
c) 1, 2 & 4
d) 1, 2 & 3

Answer: d
Clarification: Operator Short circuit AND, &&, equal to, == , ternary if-then-else, ?:, are boolean logical operators. += is an arithmetic operator it can operate only on numeric values.

4. Which of these operators can skip evaluating right hand operand?
a) !
b) |
c) &
d) &&

Answer: d
Clarification: Operator short circuit and, &&, and short circuit or, ||, skip evaluating right hand operand when output can be determined by left operand alone.

5. Which of these statements is correct?
a) true and false are numeric values 1 and 0
b) true and false are numeric values 0 and 1
c) true is any non zero value and false is 0
d) true and false are non numeric values

Answer: d
Clarification: True and false are keywords, they are non numeric values which do not relate to zero or non zero numbers. true and false are boolean values.

6. What will be the output of the following Java code?

  1.     class Relational_operator 
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             int var1 = 5; 
  6.             int var2 = 6;
  7.             System.out.print(var1 > var2);
  8.         } 
  9.     }

a) 1
b) 0
c) true
d) false

Answer: d
Clarification: Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned.
output:

$ javac Relational_operator.java
$ java Relational_operator
false

7. What will be the output of the following Java code?

  1.     class bool_operator 
  2.     {
  3.         public static void main(String args[]) 
  4.         {    
  5.              boolean a = true;
  6.              boolean b = !true;
  7.              boolean c = a | b;
  8.  	     boolean d = a & b;
  9.              boolean e = d ? b : c;
  10.              System.out.println(d + " " + e);
  11.         } 
  12.     }

a) false false
b) true ture
c) true false
d) false true

Answer: d
Clarification: Operator | returns true if any one operand is true, thus ‘c = true | false’ is true. Operator & returns a true if both of the operand is true thus d is false. Ternary operator ?: assigns left of ‘:’ if condition is true and right hand of ‘:’ if condition is false. d is false thus e = d ? b : c , assigns c to e , e contains true.
output:

$ javac bool_operator.java
$ java bool_operator
false true

8. What will be the output of the following Java code?

  1.     class ternary_operator 
  2.     {
  3.         public static void main(String args[]) 
  4.         {        
  5.              int x = 3;
  6.              int y = ~ x;
  7.              int z;
  8.              z = x > y ? x : y;
  9.              System.out.print(z);
  10.         } 
  11.     }

a) 0
b) 1
c) 3
d) -4

Answer: c
Clarification: None.
output:

$ javac ternary_operator.java
$ java ternary_operator
3

9. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {    
  5.              int x , y = 1;
  6.              x = 10;
  7.              if (x != 10 && x / 0 == 0)
  8.                  System.out.println(y);
  9.              else
  10.                  System.out.println(++y);
  11.         } 
  12.     }

a) 1
b) 2
c) Runtime error owing to division by zero in if condition
d) Unpredictable behavior of program

Answer: b
Clarification: Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error.
output:

$ javac Output.java
$ java Output
2

10. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {    
  5.              boolean a = true;
  6.              boolean b = false;
  7.              boolean c = a ^ b;
  8.              System.out.println(!c);
  9.         } 
  10.     }

a) 0
b) 1
c) false
d) true

Answer: c
Clarification: None.
output:

$ javac Output.java
$ java Output
false

250+ TOP MCQs on Methods Taking Parameters and Answers

This set of Java Questions and Answers for Entrance exams on “Methods Taking Parameters”.

1. Which of these is the method which is executed first before execution of any other thing takes place in a program?
a) main method
b) finalize method
c) static method
d) private method

Answer: c
Clarification: If a static method is present in the program then it will be executed first, then main will be executed.

2. What is the process of defining more than one method in a class differentiated by parameters?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned

Answer: b
Clarification: Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example – int volume(int length, int width) & int volume(int length , int width , int height) can be used to calculate volume.

3. Which of these can be used to differentiate two or more methods having the same name?
a) Parameters data type
b) Number of parameters
c) Return type of method
d) All of the mentioned

Answer: d
Clarification: None.

4. Which of these data type can be used for a method having a return statement in it?
a) void
b) int
c) float
d) both int and float

Answer: d
Clarification: None.

5. Which of these statement is incorrect?
a) Two or more methods with same name can be differentiated on the basis of their parameters data type
b) Two or more method having same name can be differentiated on basis of number of parameters
c) Any already defined method in java library can be defined again in the program with different data type of parameters
d) If a method is returning a value the calling statement must have a variable to store that value

Answer: d
Clarification: Even if a method is returning a value, it is not necessary to store that value.

6. What will be the output of the following Java program?

  1.     class box 
  2.     {
  3.         int width;
  4.         int height;
  5.         int length;
  6.         int volume;
  7.         void volume(int height, int length, int width) 
  8.         {
  9.              volume = width * height * length;
  10.         } 
  11.     }    
  12.     class Prameterized_method{
  13.         public static void main(String args[]) 
  14.         {
  15.             box obj = new box();
  16.             obj.height = 1;
  17.             obj.length = 5;
  18.             obj.width = 5;
  19.             obj.volume(3, 2, 1);
  20.             System.out.println(obj.volume);        
  21.         } 
  22.     }

a) 0
b) 1
c) 6
d) 25

Answer: c
Clarification: None
output:

$ Prameterized_method.java
$ Prameterized_method
6

7. What will be the output of the following Java program?

  1.     class equality 
  2.     {
  3.         int x;
  4.         int y;
  5.         boolean isequal()
  6.         {
  7.             return(x == y);  
  8.         } 
  9.     }    
  10.     class Output 
  11.     {
  12.         public static void main(String args[]) 
  13.         {
  14.             equality obj = new equality();
  15.             obj.x = 5;
  16.             obj.y = 5;
  17.             System.out.println(obj.isequal);
  18.         } 
  19.     }

a) false
b) true
c) 0
d) 1

Answer: b
Clarification: None
output:

$ javac Output.java
$ java Output 
true

8. What will be the output of the following Java program?

  1.     class box 
  2.     {
  3.         int width;
  4.         int height;
  5.         int length;
  6.         int volume;
  7.         void volume() 
  8.         {
  9.             volume = width * height * length;
  10.         } 
  11.         void volume(int x) 
  12.         {
  13.             volume = x;
  14.         }
  15.     }    
  16.     class Output 
  17.     { 
  18.         public static void main(String args[]) 
  19.         {
  20.             box obj = new box();
  21.             obj.height = 1;
  22.             obj.length = 5;
  23.             obj.width = 5;
  24.             obj.volume(5);
  25.             System.out.println(obj.volume);        
  26.         } 
  27.     }

a) 0
b) 5
c) 25
d) 26

Answer: b
Clarification: None.
output:

$ javac Output.java
$ java Output
5

9. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.         static void main(String args[]) 
  4.         {    
  5.              int x , y = 1;
  6.              x = 10;
  7.              if(x != 10 && x / 0 == 0)
  8.                  System.out.println(y);
  9.              else
  10.                  System.out.println(++y);
  11.         } 
  12.     }

a) 1
b) 2
c) Runtime Error
d) Compilation Error

Answer: d
Clarification: main() method must be made public. Without main() being public java run time system will not be able to access main() and will not be able to execute the code.
output:

$ javac Output.java
Error: Main method not found in class Output, please define the main method as:
   public static void main(String[] args)

10. What will be the output of the following Java program?

  1.     class area 
  2.     {
  3.         int width;
  4.         int length;
  5.         int height;
  6.         area() 
  7.         {
  8.         width = 5;
  9.         length = 6;
  10.         height = 1;
  11.         }
  12.         void volume() 
  13.         {
  14.              volume = width * height * length;
  15.         } 
  16.     }    
  17.     class cons_method 
  18.     {
  19.         public static void main(String args[]) 
  20.         {
  21.             area obj = new area();
  22.             obj.volume();
  23.             System.out.println(obj.volume);
  24.         } 
  25.     }

a) 0
b) 1
c) 25
d) 30

Answer: d
Clarification: None.
output:

$ javac cons_method.java
$ java cons_method
30

250+ TOP MCQs on Java.lang – Void, Process & System Class and Answers

Java MCQs on Void, Process & System classes of Java Programming Language.

1. Which of these class have only one field ‘TYPE’?
a) Void
b) Process
c) System
d) Runtime

Answer: a
Clarification: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

2. Which of the following method of Process class can terminate a process?
a) void kill()
b) void destroy()
c) void terminate()
d) void exit()

Answer: b
Clarification: Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.

3. Standard output variable ‘out’ is defined in which class?
a) Void
b) Process
c) Runtime
d) System

Answer: d
Clarification: Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().

4. Which of these class can encapsulate an entire executing program?
a) Void
b) Process
c) Runtime
d) System

Answer: b
Clarification: None.

5. Which of the following is method of System class is used to find how long a program takes to execute?
a) currenttime()
b) currentTime()
c) currentTimeMillis()
d) currenttimeMillis()

Answer: c
Clarification: None.

6. Which of these class holds a collection of static methods and variables?
a) Void
b) Process
c) Runtime
d) System

Answer: d
Clarification: System class holds a collection of static methods and variables. The standard input, output and error output of java runtime is stored in the in, out and err variables of System class.

7. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             long start, end;   
  6.             start = System.currentTimeMillis();
  7.             for (int i = 0; i < 10000000; i++);
  8.             end = System.currentTimeMillis();
  9.             System.out.print(end - start);
  10.         }
  11.     }

a) 0
b) 1
c) 1000
d) System Dependent

Answer: d
Clarification: end time is the time taken by loop to execute it can be any non zero value depending on the System.
Output:

$ javac Output.java
$ java Output
78

8. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a , 0, b, 0, a.length);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL

Answer: a
Clarification: System.arraycopy() is a method of class System which is used to copy a string into another string.
Output:

$ javac Output.java
$ java Output
ABCDEF ABCDEF

9. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a, 2, b, 1, a.length-2);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL

Answer: b
Clarification: None.
Output:

$ javac Output.java
$ java Output
ABCDEF GCDEFL

10. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a, 1, b, 3, 0);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL

Answer: a
Clarification: Since last parameter of System.arraycopy(a,1,b,3,0) is 0 nothing is copied from array a to array b, hence b remains as it is.
Output:

$ javac Output.java
$ java Output
ABCDEF GHIJKL

250+ TOP MCQs on Serialization – 1 and Answers

This set of Java Multiple Choice Questions & Answers (MCQs) on “Serialization – 1”.

1. Which of these is a process of writing the state of an object to a byte stream?
a) Serialization
b) Externalization
c) File Filtering
d) All of the mentioned

Answer: a
Clarification: Serialization is the process of writing the state of an object to a byte stream. This is used when you want to save the state of your program to a persistent storage area.

2. Which of these process occur automatically by the java runtime system?
a) Serialization
b) Garbage collection
c) File Filtering
d) All of the mentioned

Answer: a
Clarification: Serialization and deserialization occur automatically by java runtime system, Garbage collection also occur automatically but is done by CPU or the operating system not by the java runtime system.

3. Which of these is an interface for control over serialization and deserialization?
a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput

Answer: b
Clarification: None.

4. Which of these interface extends DataOutput interface?
a) Serializable
b) Externalization
c) ObjectOutput
d) ObjectInput

Answer: c
Clarification: ObjectOutput interface extends the DataOutput interface and supports object serialization.

5. Which of these is a method of ObjectOutput interface used to finalize the output state so that any buffers are cleared?
a) clear()
b) flush()
c) fflush()
d) close()

Answer: b
Clarification: None.

6. Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?
a) write()
b) Write()
c) StreamWrite()
d) writeObject()

Answer: d
Clarification: writeObject() is used to write an object into invoking stream, it can be input stream or output stream.

7. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class serialization 
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6.             try 
  7.             {
  8.                 Myclass object1 = new Myclass("Hello", -7, 2.1e10);
  9. 	        FileOutputStream fos = new FileOutputStream("serial");
  10. 	        ObjectOutputStream oos = new ObjectOutputStream(fos);
  11.                 oos.writeObject(object1);
  12.                 oos.flush();
  13.                 oos.close();
  14. 	    }
  15. 	    catch(Exception e) 
  16.             {
  17. 	        System.out.println("Serialization" + e);
  18.                 System.exit(0);
  19.             }
  20. 	    try  
  21.             {
  22.                 Myclass object2;
  23. 	        FileInputStream fis = new FileInputStream("serial");
  24. 	        ObjectInputStream ois = new ObjectInputStream(fis);
  25.                 object2 = (Myclass)ois.readObject();
  26.                 ois.close();
  27. 	        System.out.println(object2);		    	
  28. 	    }
  29. 	    catch (Exception e) 
  30.             {
  31.                 System.out.print("deserialization" + e);
  32. 	        System.exit(0);
  33. 	    }
  34.         }
  35.     }
  36.     class Myclass implements Serializable 
  37.     {
  38. 	String s;
  39. 	int i;
  40. 	double d;
  41.         Myclass (String s, int i, double d)
  42.         {
  43. 	    this.d = d;
  44. 	    this.i = i;
  45. 	    this.s = s;
  46. 	}
  47.     }

a) s=Hello; i=-7; d=2.1E10
b) Hello; -7; 2.1E10
c) s; i; 2.1E10
d) Serialization

Answer: a
Clarification: None.
Output:

$ javac serialization.java
$ java serialization
s=Hello; i=-7; d=2.1E10

8. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class serialization 
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6.             try 
  7.             {
  8.                 Myclass object1 = new Myclass("Hello", -7, 2.1e10);
  9. 	        FileOutputStream fos = new FileOutputStream("serial");
  10. 	        ObjectOutputStream oos = new ObjectOutputStream(fos);
  11.                 oos.writeObject(object1);
  12.                 oos.flush();
  13.                 oos.close();
  14. 	    }
  15. 	    catch(Exception e) 
  16.             {
  17. 	        System.out.println("Serialization" + e);
  18.                 System.exit(0);
  19.             }
  20. 	    try
  21.             {
  22. 	        int x;
  23. 	        FileInputStream fis = new FileInputStream("serial");
  24. 	        ObjectInputStream ois = new ObjectInputStream(fis);
  25.                 x = ois.readInt();
  26.                 ois.close();
  27. 	        System.out.println(x);		    	
  28. 	    }
  29. 	    catch (Exception e)
  30.             {
  31.                 System.out.print("deserialization");
  32. 	        System.exit(0);
  33. 	    }
  34.         }
  35.     }
  36.     class Myclass implements Serializable
  37.     {
  38. 	String s;
  39. 	int i;
  40. 	double d;
  41.         Myclass(String s, int i, double d)
  42.         {
  43. 	    this.d = d;
  44. 	    this.i = i;
  45. 	    this.s = s;
  46. 	}
  47.     }

a) -7
b) Hello
c) 2.1E10
d) deserialization

Answer: d
Clarification: x = ois.readInt(); will try to read an integer value from the stream ‘serial’ created before, since stream contains an object of Myclass hence error will occur and it will be catched by catch printing deserialization.
Output:

$ javac serialization.java
$ java serialization
deserialization

9. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class Chararrayinput
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6. 	    String obj  = "abcdefgh";
  7.             int length = obj.length();
  8.             char c[] = new char[length];
  9.             obj.getChars(0, length, c, 0);
  10.             CharArrayReader input1 = new CharArrayReader(c);
  11.             CharArrayReader input2 = new CharArrayReader(c, 1, 4);
  12.             int i;
  13.             int j;
  14.             try 
  15.             {
  16. 		while ((i = input1.read()) == (j = input2.read()))
  17.                 {
  18.                     System.out.print((char)i);
  19.                 }
  20.        	    } 
  21.             catch (IOException e) 
  22.             {
  23.                 e.printStackTrace();
  24. 	    }
  25. 	}
  26.     }

a) abc
b) abcd
c) abcde
d) None of the mentioned

Answer: d
Clarification: No output is printed. CharArrayReader object input1 contains string “abcdefgh” whereas object input2 contains string “bcde”, when while((i=input1.read())==(j=input2.read())) is executed the starting character of each object is compared since they are unequal control comes out of loop and nothing is printed on the screen.
Output:

$ javac Chararrayinput.java
$ java Chararrayinput

10. What will be the output of the following Java program?

  1.     import java.io.*;
  2.     class streams
  3.     {
  4.         public static void main(String[] args) 
  5.         {
  6.             try
  7.             {
  8. 	        FileOutputStream fos = new FileOutputStream("serial");
  9. 	        ObjectOutputStream oos = new ObjectOutputStream(fos);
  10.                 oos.writeFloat(3.5);
  11.                 oos.flush();
  12.                 oos.close();
  13. 	    }
  14. 	    catch(Exception e)
  15.             {
  16. 	        System.out.println("Serialization" + e);
  17.                 System.exit(0);
  18.             }
  19. 	    try 
  20.             {
  21. 	        float x;
  22. 	        FileInputStream fis = new FileInputStream("serial");
  23. 	        ObjectInputStream ois = new ObjectInputStream(fis);
  24.                 x = ois.readInt();
  25.                 ois.close();
  26. 	        System.out.println(x);		    	
  27. 	    }
  28. 	    catch (Exception e)
  29.             {
  30.                 System.out.print("deserialization");
  31. 	        System.exit(0);
  32. 	    }
  33.         }
  34.     }

a) 3
b) 3.5
c) serialization
d) deserialization

Answer: b
Clarification: oos.writeFloat(3.5); writes in output stream which is extracted by x = ois.readInt(); and stored in x hence x contains 3.5.
Output:

$ javac streams.java
$ java streams
3.5