Core Java Interview Questions-Packages

This Core Java Interview Questions-Packages page provides all the interview questions about java packages including package creation, default package in Java, accessing same package members, accessing outside package members, import keyword, fully qualified name, importing sub packages and creation of sub packages.

What is Java package?
The package is a java folder or directory.

What a java package holds?
the package is a set of related classes, abstract classes, and interfaces.

What is the default package in Java?
“lang” package is the default package.
“lang” package classes are directly available into every java application.
“lang” package classes we can implement basic programming in java.

How to access one class members from another class of the same package?
In java default access permissions are package level hence we can access one class members
directly from another class if both the classes belong to the same package.

What is the default access modifier of the constructor if the class is public?
if the class is package level, the default constructor is also package level.
if the class in public, default constructor is public.

What is the use of “import” keyword?
“import” is used to connect the class files of different packages in java application.

Will import statement loads the class directly?
import statement doesn’t load the class directly into memory.
It creates an internal pointer to the package by which classes will be loaded at runtime.

Do we need to define a class with the same name of the file name?
No, if it is package level class
Yes, if it is a public class.

Can we define more than one public class in a single java source file?
If the class is “public”, we must save with the same name of the class name.
Hence we cannot place 2 class files in a single java source file of public type.

What is “Fully Qualified Name”?
Writing complete package name while using any class in java application.

Can we replace import statement using the Fully qualified name?
Yes, we can.

What is the advantage of Fully Qualified Name?
We can access duplicate classes of different packages only by using “Fully Qualified Name”.

Can we define user class with identity System?
Yes allowed.
We can access these classes using “Fully Qualified Name”

What is “Class Loader Sub System”?
It is responsible for loading the class files into JVM when we use.

How Class loader loads the class into JVM?
It gives first priority to Current Working Directory to load the class and then searches in API.

Can we access sub package class by importing super package?
Not allowed.
We must import sub packages explicitly to access class members of sub package.

How can we create sub packages?
We can create sub-packages using “package” keyword as follows.
Syntax : package outer_package.inner_package
Ex : package maths.operators.arithmetic ;

>Core Java Interview Questions-Polymorphism<

Share this