Java - Interview Questions and Answers on Packages

Q1.  What does the default access specifier means ?

Default - Accessible from anywhere within same package.

Q2.  Can I import same package/class twice? Will the JVM load the package twice at runtime?

Ans. One can import the same package or same class multiple times. Neither compiler nor JVM complains wil complain about it. And the JVM will internally load the class only once no matter how many times you import the same class.

Q3.  Do we need to import java.lang.package ?

Ans. No, It is loaded by default by the JVM.

Q4.  What is the difference between public class and class ?

Ans. Class without any access specifier has the default scope i.e it can be accessed by any class within same package. 

Class declared public can be accessed from anywhere.

Q5.  Name few classes that are part of package ?


Q6.  Name few classes that are part of java.lang package ?


Q7.  Name few classes that are part of java.util package ?