• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem of Exception handling at compile time

 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,



 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey the problem is solved.

Thank you.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am also very curious to know.please post your solution.

Cheers Munees

My Blog
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic