Hello, every helper:
I got another three problems in go4java. Would you please help?
1)1. class Q43
2. {
3. int y=1;
4. Q43()
5. {
6. this(y);
7. }
8. Q43(int x)
9. {
10. y=x++ + ++x;
11. }
12. public static void main(
String [] args)
13. {
14. Q43 t = new Q43();
15. System.out.println(t.y);
16. }
17. }
The answer is "It will give you compile time error as you cannot reference y before super class constructor has been called". I don't understand why it has relation with super class.
I think it should compile correctly and print 4.
2) 1. public class Q45
2. {
4. static
5. {
6. System.out.print("Java".startsWith(""));
7. }
8. static void processorB()
9. {
10. System.out.println(" is a boolean Operator.");
11. }
12. static Q45 processorA()
13. {
14. Q45 q=null;
15. if (("java").startsWith("null"))
16. return q;
17. else
18. return null;
19. }
20. public static void main(String[] args)
21. {
22. processorA().processorB();
23. }
24. }
The answer is "Program will compile correctly and print true is a boolean operator when executed. ". Why is there no NullPointerException? Is it because processorB() is static? If so , then we can use null object of a class to invoke its static method at any time?
3)Why don't we need to throw Exception before catching it, while if "class Except extends Exception{}" and we want to catch Except, then we must first throws it?
4) Anybody knows any site stating about initializer block and static initializer block? I am new to that.
Thanks, everyone. Have a good day.