how many
String objects are created when we run the
following code
String s1,s2,s3,s4;
s1 = "Hello";
s2 = s1;
s3 = s2 + "Pal";
s4 = s3;
A. 1
b. 2
c. 3
d. 4
e. we can't say.
they have given the answser is C.Four string objects are created. so how come the answer is 3.CanAnybody explain?
q.2
which of the following are valid constructors of the class named 'SubClass' which extends a class with defualt constructor.
A.public SubClass (int i) {
this();
}
B.public SubClass (int i) {
super();
this();
}
C. private SubClass(int i) {
super();
}
D. protected SubClass(int i) {
this();super();
}
in Q.2 which answer is correct and why? please explain.
Q.3
1. class HasStatic
2. {
3. private static int x = 100;
4.
5. public static void main(String args[])
6. {
7. HasStatic hs1 = new HasStatic();
8. hs1.x++;
9. HasStatic hs2 = new HasStatic();
10. hs2.x++;
11. hs1 = new HasStatic();
12. hs1.x++;
13. HasStatic.x++;
14. System.out.println("x = " + x);
15. }
16. }
in Q.3 the code gets compiled and the output is 104.My question is the compiler should throw an exception at line.11 beacause of creating a object with same name.