aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem of Exception handling at compile time 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 "Problem of Exception handling at compile time" Watch "Problem of Exception handling at compile time" New topic
Author

Problem of Exception handling at compile time

dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Hi all,


Problem:

During compilation error called inconvertible types.

There is no relation between class A and class C.

Then c instance of A line seems to be false.

But when i run the code seems to be no error.

Thank you.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hi Dimple,

Please QuoteYourSources for the above snippet of code.

If you see the snippet of code above, it will give un-convertible types. Look at this snippet


The error must be first coming when you will be assigning c to to ref variable. You can't do that, because C extends B and
in turn B doesn't extends A, so they are inconvertible types. So you cannot assign c to A.

Well, what do you mean by it runs fine and doesn't give any error. Are you talking about this statement


Even at this line, it's going to give you an error of in convertible types.

Point out which part do you mean is running fine.

Hope this helps,




Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
I know the line

c instance of A ------------- is incorrect


Since class C do not extend A .

When i compile the code i get the error that they are inconvertible types which is fine.

But same code when i run means---------- java MyInstance --------- it gives me the desired output



Which should not be obtained.


You can try:

First compile the code we get an error

In spite of the error run the code output is obtained.

I am not able to understand how come the code runs fine in spirte of compile error.
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
I am not able to understand why you got that. When there are compiler errors, when you run it you will get an error. This is what i got when i run your code

dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Hey the problem is solved.

Thank you.
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Could you please let me know how did you manage to get an output when you have compiler errors? I am curious to know
Muneeswaran Balasubramanian
Ranch Hand

Joined: Mar 19, 2010
Posts: 138
Hi,
I am also very curious to know.please post your solution.

Cheers Munees

My Blog


Cheers Munees
My Blog
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hi,

I am curious as well like Bhanu and Munee.

Do share, how did you manage to run the code, when it was not compiled?

Cheers,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem of Exception handling at compile time