Explore topic-wise MCQs in Java Programming.

This section includes 44 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of the below Java program with packages?

A. No output
B. Compiler error
C. 484 (some random number)
D. None
Answer» D. None
2.

What are the uses of a Java Package?

A. A package contains ready-to-use classes written for a specific purpose.
B. Packages are easy to distribute your code. It is nothing but reusability. Instead of writing code afresh, you can take advantage of the existing classes of a package. Simply import it and use.
C. Packages help in maintaining the code easily. Each sub-package may be maintained for more specific purposes. You can reuse the class names in sub-packages or other packages without name clash.
D. All the above
Answer» E.
3.

Accessing the variables, constants, or methods of a class, imported from a package is subjective to access modifiers like PUBLIC, PRIVATE, PROTECTED and default. State TRUE or FALSE.

A. TRUE
B. FALSE
C. -
D. -
Answer» B. FALSE
4.

Choose a correct statement about using the classes or interfaces or abstract classes inside the packages in our Java program.

A. You can extend the class imported from the package.
B. You can implement the interfaces imported from the package.
C. You can extend the abstract classes imported from the package.
D. All the above
Answer» E.
5.

Which is the symbol used to separate a super-package and a sub-package at the time of declaring or importing in a Java program?

A. Dollar ($)
B. Pound (#)
C. Period (.) or DOT
D. Arrow (->)
Answer» D. Arrow (->)
6.

Choose a correct way of importing all the classes in the below java program with packages.

A. import animals.*;
B. import animals.cat;
C. Both A and B
D. None
Answer» D. None
7.

What are the popular Classes or Interfaces inside a Java Language Pack (java.lang)?

A. Byte, Character, Short, Integer, Float, Long, Number
B. Math, String, StringBuffer, StringBuilder
C. Thread, Throwable, Exception, Error
D. All the above
Answer» E.
8.

Which is the default Java package that will be auto included (imported) in the classpath while Compiling and Running a Java program?

A. java.io
B. java.util
C. java.net
D. java.lang
Answer» E.
9.

How does JAVAC or JAVA (JVM) find the packages that will be used inside classes by an import statement?

A. If the packages are defined on the same root level as the compiling or running class file, Java knows it.
B. You should manually use the CLASSPATH or CP command to include the path of the package or single-class for compiling and running
C. You can copy the JAR files in LIB folder of Java inside Program Files
D. All the above
Answer» E.
10.

You can place a comment before the Package Declaration statement in Java. State TRUE or FALSE.

A. TRUE
B. FALSE
C. -
D. -
Answer» B. FALSE
11.

The package declaration statement should be the first statement in a Java file. State TRUE or FALSE.

A. TRUE
B. FALSE
C. -
D. -
Answer» B. FALSE
12.

When importing a Package, the Class is actually importing ____.

A. Classes or Interfaces from the package
B. Constants
C. Methods
D. None of the above
Answer» B. Constants
13.

Choose a correct statement below about importing packages into a class.

A. A Java class or interface can import any number of packages.
B. It is advised to import only the required Classes of a package to save memory.
C. Java packages are usually distributed in the form of JAR files.
D. All the above
Answer» E.
14.

What is the maximum number of levels or depth up to which sub-packages can be defined in Java?

A. 8
B. 16
C. 32
D. There is no limit
Answer» E.
15.

You can use the same name for a Parent package and Child package in Java. State TRUE or FALSE.

A. TRUE
B. FALSE
C. -
D. -
Answer» B. FALSE
16.

Choose correct declaration and importing of packages in Java.

A. package SOMEPACKAGE;
B. import PACKAGE_N.*;
C. import PACKAGE_M.*;
D. All the above
Answer» B. import PACKAGE_N.*;
17.

Which is the correct syntax to import a Java package below?

A. import PACKAGE1.*;
B. import PACKAGE1.CLASS1;
C. import PACKAGE1.PACKAGE2.PACKAGE3.*;
D. All the above
Answer» E.
18.

The keyword used to import a package into Java class or Interface is ___.

A. import
B. download
C. use
D. None of the above
Answer» B. download
19.

It is possible to declare a package and import another package within the same Java class file. State TRUE or FALSE.

A. TRUE
B. FALSE
C. -
D. -
Answer» B. FALSE
20.

The name of a package is the name of the ___ in Java.

A. folder
B. All parent folders separated by DOT symbols
C. All parent packages separated by DOT symbols
D. All the above
Answer» E.
21.

Can you compile a Java file kept inside a directory without mentioning the package name?

A. Yes
B. No
C. -
D. -
Answer» B. No
22.

What is the maximum number of Java Class files that can be kept inside a single Java Package?

A. 8
B. 64
C. 128
D. Unlimited
Answer» E.
23.

The keyword used to declare a Java package is ____.

A. pkg
B. package
C. pkge
D. None of the above
Answer» C. pkge
24.

Choose the correct syntax of a Java Package below.

A. package PACKAGE_NAME;
B. package PACKAGE_NAME.*;
C. pkg PACKAGE_NAME;
D. pkg PACKAGE_NAME.*;
Answer» B. package PACKAGE_NAME.*;
25.

What is a package in Java?

A. A Package is a collection of files of type Java Class, Interfaces, or Abstract Class
B. A Package is simply a Directory or Folder with Java Classes
C. A Package usually contains Java Classes written for a specific purpose or problem
D. All the above
Answer» E.
26.

What is the length of the application box made by this program?

A. 20
B. Default value
C. Compilation Error
D. Runtime Error
Answer» D. Runtime Error
27.

Which of the following packages is used to includes classes to create user interface like Button and Checkbox?

A. java.lang
B. java.net
C. java.awt
D. java.io
Answer» D. java.io
28.

Can "abstract" keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.

A. True
B. False
C. May be True or False
D. Can't Say
Answer» C. May be True or False
29.

Package in Java is a mechanism to encapsulate a ______________.

A. Classes
B. Sub Packages
C. Interfaces
D. All of the above
Answer» E.
30.

Which of the following is false statement about package in java?

A. Packages are used for preventing naming conflicts
B. Providing controlled access: protected and default have package level access control.
C. Packages cannot be considered as data encapsulation
D. both a and c
Answer» D. both a and c
31.

A java interface can contain _______.

A. Abstract methods(unimplemented) and implemented methods both
B. public Abstract methods
C. public static Final Variables only
D. public static Final Variables and abstract methods both
Answer» E.
32.

Which of the following packages is used to includes utility classes like Calendar, Collection, Date?

A. java.lang
B. java.net
C. java.awt
D. java.util
Answer» E.
33.

Which of the following is the correct way of importing an entire package "pkg"?

A. import pkg.
B. Import pkg.
C. import pkg.*
D. Import pkg.*
Answer» D. Import pkg.*
34.

Which of the following is true about methods in an interface in java?

A. An interface can contain only abstract method.
B. We can define a method in an interface
C. Private and protected access modifiers can also be used to declare methods in interface
D. None of the above
Answer» B. We can define a method in an interface
35.

Packages that are inside another package are the _________

A. packages
B. nested packages
C. util subpackages
D. subpackages
Answer» E.
36.

Package names and directory structure are closely related.

A. True
B. False
C. May be True or False
D. Can't Say
Answer» B. False
37.

Which of the following classes directly implement Set interface?

A. Vector
B. HashSet
C. HashTable
D. LinkedList
Answer» C. HashTable
38.

Which is the correct way to inherit and implement the interface?

A. class Cat implements IAnimal{}
B. class Cat import IAnimal{}
C. class Cat extends IAnimal{}
D. None is correct
Answer» B. class Cat import IAnimal{}
39.

An _______________ statement can be used to access the classes and interface of a different package from the current package.

A. instanceOf
B. import
C. extends
D. implement
Answer» C. extends
40.

Can “abstract” keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.

A. True
B. False
C. May be
D. Can't say
Answer» C. May be
41.

Which of the following is an incorrect statement regarding the use of generics and parameterized types in Java?

A. Generics provide type safety by shifting more type checking responsibilities to the compiler
B. Generics and parameterized types eliminate the need for down casts when using Java Collections
C. When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes
D. All of the mentioned
Answer» D. All of the mentioned
42.

What is the output of this program?Note : packages.class file is in directory pkg;

A. 0
B. 1
C. 2
D. 0 1 2
Answer» D. 0 1 2
43.

Which of the following is the correct way of importing an entire package ‘pkg’?

A. import pkg.
B. Import pkg.
C. import pkg.*
D. Import pkg.*
Answer» D. Import pkg.*
44.

What is the output of this program?Note : Output.class file is not in directory pkg.

A. HelloGoodWorld
B. HellGoodoWorld
C. Compilation error
D. Runtime error
Answer» E.