jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about import 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 "about import" Watch "about import" New topic

about import

wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
Question 196)
Read the code below carefully.
import com.abhilash.abhilash;
public class One
public static void main()
abhilash a = new abhilash();
The code will fail to compile. The class com.abhilash.abhilash can never be imported.
The code will compile. Runtime error occurs if one of the class in the import does not exist and is referenced.
The code will compile and run with out any problem.
the ans is 1st. why? the first abhilash is package,the second is class, is there anything wrong with it?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi wei,
If there really is a public class 'com.abhilash.abhilash' and it's in the classpath the code will compile properly. Won't run however as 'main()' isn't declared properly.
A class can have the same name as a package or subpackage; there is no conflict.
Hope that helps.
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link: http://aspose.com/file-tools
subject: about import
It's not a secret anymore!