Hi Smitha,
Well the questions you've listed are fairly simple to understand and reason. I wish we get such questions in the real exam too.
Well here are the answers:
Answer to your first question:
The code fails to compile. The compiler complains that the assignment "s1 = (Subclass1)s2" is illegal.
This is simply because Subclass1 and Subclass2 are peer classes. Peer classes do not have knowledge about each other. So if you try to cast from one peer class to the other, the compiler will complain. I hope you know what are peer classes :
B a s e
/ \
Subclass1 Subclass2
Subclass1 and Subclass2 are peers so an object of Subclass1 will not have any idea of an object of Subclass2.
Answer to your second question:
1.public transient static final int _FRAMEX = 850; //Is absolutely fine
2.this("a", "b"); // Is absolutely fine
3.private transient static final int _FRAMEX = 850; //Is absolutely fine
4.boolean b = 0; // Is ERRONEOUS
5.short s=128; //Is absolutely fine
6.int x=(int)(1.23); //Is absolutely fine.
Why ? Because a boolean variable can have only values true or false. 0 is an integer so it cannot be assigned to boolean.
Answer to your next question:
If null is passed , Is
string version executed ?
Yes.
And the answer to your last question
Why code does not compile ?
Because bo the methods method(StringBuffer sb) and method(String s) take objects of String type so the compiler complains that methods are ambiguous.
Hope this helps