Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with go4java again

 
wei luo
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jason Li
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, wei luo,
For your first question, you can't pass any instance variable to this(), i guess also super(). Please see JLS 8.8.5.1.
Question 2, yes, y r right.
For any checked exception, we must throw it, then catch it. But not for runtime exception.
For initializer, please read JLS 12.4 and 12.5. That's the best with examples.
 
wei luo
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Jason.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic