1

Java Packages

Question 1
Which of the following is/are true about packages in Java?
1) Every class is part of some package. 
2) All classes in a file are part of the same package. 
3) If no package is specified, the classes in the file 
   go into a special unnamed package 
4) If no package is specified, a new package is created with 
   folder name of class and the class is put in this package. 
A
Only 1, 2 and 3
B
Only 1, 2 and 4
C
Only 4
D
Only 1 and 3
Java Packages    
Discuss it


Question 1 Explanation: 
In Java, a package can be considered as equivalent to C++ language's namespace.
Question 2
Which of the following is/are advantages of packages?
A
Packages avoid name clashes
B
Classes, even though they are visible outside their package, can have fields visible to packages only
C
We can have hidden classes that are used by the packages, but not visible outside.
D
All of the above
Java Packages    
Discuss it


Question 3
Predict the output of following Java program
// Note static keyword after import.
import static java.lang.System.*;
  
class StaticImportDemo
{
   public static void main(String args[])
   {      
        out.println("GeeksforGeeks");
   }
}
A
Compiler Error
B
Runtime Error
C
GeeksforGeeks
D
None of the above
Java Packages    
Discuss it


Question 3 Explanation: 
There are 3 questions to complete.
1


Please do Like/Share if you find the above useful. Also, please do leave us comment for further clarification or info. We would love to help and learn 🙂

Company Wise Coding Practice    Topic Wise Coding Practice