top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Are the imports checked for validity at compile time?

–4 votes
519 views

e.g. will the code containing an import such as java.lang.ABCD compile?

posted Mar 26, 2014 by Prachi Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Let me google it for you and found first link (may be a famous interview question)

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol

symbol : class ABCD
location: package io
import java.io.ABCD;
answer Mar 26, 2014 by Luv Kumar
Similar Questions
+2 votes

I assume that constant must be initialized to a constant value at compile time, but following code the return value of ge_const() is assigned to x which will be collected at run time. So this must cause an error but I am getting the output as 50. Can someone clarify the detail?

main()
{
    const int x = get_const();
    printf("%d", x);
}
int get_const()
{
    return 50;
}
–2 votes

e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?

...