Java Packages Quiz

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. 
Tick
Only 1, 2 and 3
Cross
Only 1, 2 and 4
Cross
Only 4
Cross
Only 1 and 3


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?
Cross
Packages avoid name clashes
Cross
Classes, even though they are visible outside their package, can have fields visible to packages only
Cross
We can have hidden classes that are used by the packages, but not visible outside.
Tick
All of the above


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");
   }
}
Cross
Compiler Error
Cross
Runtime Error
Tick
GeeksforGeeks
Cross
None of the above


Question 3-Explanation: 
Question 4

Which of the following statement(s) is/are TRUE regarding Java Servlets? (a) A Java Servlet is a server-side component that runs on the web server and extends the capabilities of a server. (b) A Servlet can use the user interface classes like AWT or Swing.

Tick

Only (a) is TRUE.

Cross

Only (b) is TRUE.

Cross

Both (a) and (b) are TRUE.

Cross

Neither (a) nor (b) is TRUE.



Question 4-Explanation: 

A Java Servlet is a server-side component that runs on the web server and extends the capabilities of a server. It is correct statement.
A Java servlet can't be use interfaces classes like AWT or Swing. only first statement is correct. 
for detailed information Refer:JAVA_ servlet 
So, option (A) is correct.

Question 5
Which one of the following is correct?
Cross
Java applets can not be written in any programming language
Cross
An applet is not a small program
Cross
An applet can be run on its own
Tick
Applets are embedded in another applications


Question 5-Explanation: 
  • Java applets can not be written in any programming language. IncorrectIt can be written in other programming language.
  • An applet is not a small program. Incorrect It is a small program.
  • An applet can be run on its own. Incorrect No applet don't run on its own.
  • Applets are embedded in another applications. Correct. Yes applets are embedded in another application
  • For more infor mation on applet Refer:Java Applet Basics Option (D) is correct.
    There are 5 questions to complete.

    • Last Updated : 27 Sep, 2023

    Share your thoughts in the comments
    Similar Reads