Sunday, August 14, 2011

Java Questions - 42

Read the following program:

public class test {
public static void main(String [] args) {
    int x = 3;
    int y = 1;
    if (x = y)
        System.out.println("Not equal");
   else
        System.out.println("Equal");
  }
}

What is the result?
The output is “Equal”
B. The output in “Not Equal”
C. An error at " if (x = y)" causes compilation to fall.
D. The program executes but no output is show on console.
Answer: C
Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

No comments: