Source File Structure

Source File Structure

We just focusing about Source File Structure which is the kind of import and package issues .The following legal code declares a class Foo, in package com.geeksanonymous : 

package com.geeksanonymous; // Notice the semicolon
class Foo { }

Here in this code its singing a only one package statement per source cod file , that\'s are following as :

package com.geeksanonymous;
package com.wickedlysmart; // Illegal! Only one package declaration allowed
class Foo { }

If class Foo adds any import statement then the code is :
 package com.geeksanonymous;
import java.util.*; // Wildcard package import
import com.wickedlysmart.Foo; // Explicit class import
class Foo { }
 
If the Class Foo dont have a package then the import statements must be above the:

class declarationof the above code .as folows :
import java.util.*; // Wildcard package import
import com.wickedlysmart.Foo; // Explicit class import
class Foo { }

By:UMANG
Date:2025-02-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher