About Question enthuware.ocajp.i.v7.2.834 :
Moderator: admin
-
- Posts: 25
- Joined: Wed Dec 17, 2014 9:29 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.834 :
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?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.834 :
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.
-
- Posts: 25
- Joined: Wed Dec 17, 2014 9:29 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.834 :
Thank you, I will try it ))
-
- Posts: 32
- Joined: Mon Dec 29, 2014 4:14 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.834 :
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:
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();
}
}
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.834 :
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.
-
- Posts: 32
- Joined: Mon Dec 29, 2014 4:14 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.834 :
Thank you, I overlooked compile
Now is clear
Now is clear
Who is online
Users browsing this forum: No registered users and 129 guests