File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help with go4java again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help with go4java again" Watch "help with go4java again" New topic

help with go4java again

wei luo

Joined: Mar 15, 2001
Posts: 23
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

Joined: Jun 24, 2001
Posts: 46
Hi, wei luo,
For your first question, you can't pass any instance variable to this(), i guess also super(). Please see JLS
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.

green horn
wei luo

Joined: Mar 15, 2001
Posts: 23
Thank you, Jason.
I agree. Here's the link:
subject: help with go4java again
jQuery in Action, 3rd edition