views:

43

answers:

1

for example Class B extends A. An object A test= new B (x,y); Then a method that there is only on Class B is invoked on the test object. Will it be a Compile time error or a run time error? Overall what are the different between both errors.

+1  A: 

It's a compile time error. (See here)

A compile time error is when the compiler can't understand what you wanted to do.
There is a lot of conditions to have a compile-time error but basically it's when the syntax you used either confuses the compiler or isn't valid at all.

Colin Hebert
How would this be a syntax error? More a "you're using it but I can't prove that it's there" error. But that's still a compiletime error, so I'm just being pedantic :)
delnan
@delnan, as the Java Language Specification specifies that a method must exist to be called, it's a syntax error for the java language ;)
Colin Hebert
Thanks Colin. When will it be a runtime error?
gbox
Well most of the time when the compiler can't detect the error itself and when the syntax is correct but what you want to do isn't (accessing an invalid index of an array for example)
Colin Hebert