About Question enthuware.ocajp.i.v7.2.834 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
coder007
Posts: 25
Joined: Wed Dec 17, 2014 9:29 pm
Contact:

About Question enthuware.ocajp.i.v7.2.834 :

Post by coder007 »

Calling method has to declare in its trows clause the same exception as in the source method, or it could be a super class of that exception?

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.834 :

Post by admin »

It could be a super class also. You should try it out.
If you like our products and services, please help us by posting your review here.

coder007
Posts: 25
Joined: Wed Dec 17, 2014 9:29 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.834 :

Post by coder007 »

Thank you, I will try it ))

Dreamweaver
Posts: 32
Joined: Mon Dec 29, 2014 4:14 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.834 :

Post by Dreamweaver »

The question is: What changes can be done to make the above code compile?
And the correct answer: Change declaration of all the three method to include throws Exception.

But for me it does not compile:
Exception in thread "main" java.lang.Exception
at com.teo.exam.tt.TestClass.yourMethod(TestClass.java:14)
at com.teo.exam.tt.TestClass.myMethod(TestClass.java:10)
at com.teo.exam.tt.TestClass.main(TestClass.java:6)

Code: Select all

public class TestClass {
    public static void main(String[] args) throws Exception {
        TestClass tc = new TestClass();
        tc.myMethod();
    }

    public void myMethod() throws Exception {
        yourMethod();
    }

    public void yourMethod() throws Exception {
        throw new Exception();
    }
}

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.834 :

Post by admin »

What you have posted is the exception stack trace generated by the JVM. That means compilation succeeded. Right?
If you like our products and services, please help us by posting your review here.

Dreamweaver
Posts: 32
Joined: Mon Dec 29, 2014 4:14 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.834 :

Post by Dreamweaver »

Thank you, I overlooked compile
Now is clear

Post Reply

Who is online

Users browsing this forum: No registered users and 111 guests