Explore topic-wise MCQs in Java Programming.

This section includes 26 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.

____________method can be given parameters via using command line arguments.

A. main()
B. recursive()
C. System defined methods
D. Any method
Answer» B. recursive()
2.

Which of the following statements is true?

A. It is sometimes good practice to throw an AssertionError explicitly.
B. Private getter() and setter() methods should not use assertions to verify arguments.
C. If an AssertionError is thrown in a try-catch block, the finally block will be bypassed.
D. It is proper to handle assertion statement failures using a catch (AssertionException ae) block.
Answer» B. Private getter() and setter() methods should not use assertions to verify arguments.
3.

Number of arguments can be passed to main() is?

A. 1
B. 2
C. 3
D. Infinite
Answer» E.
4.

How many objects are eligible for garbage collection after execution of line?

A. 0
B. 1
C. 2
D. 3
Answer» D. 3
5.

What is the output for the following code, when you passed compsciedu at run time?

A. java
B. CommandLineExample{
C. arg[0]
D. compsciedu
Answer» E.
6.

How many objects are eligible for garbage collection after execution of line 8?

A. 0
B. 1
C. 2
D. 3
Answer» C. 2
7.

What is the outcome of below Main class?

A. Compilation failure
B. Runtime failure
C. 1
D. 2
Answer» E.
8.

What is the correct option with regards to below snippet?

A. ICust can be replaced with RegularCustomer
B. RegularCustomer can be replaced with OneTimeCustomer
C. OneTimeCustomer can be replaced with RegularCustomer
D. We can instantiate objects of ICust
Answer» B. RegularCustomer can be replaced with OneTimeCustomer
9.

What is the outcome of below code Main class?

A. Compilation failure
B. 3
C. Runtime Exception
D. 2
Answer» C. Runtime Exception
10.

What is the output of this program?Note : The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).

A. z
B. Jul
C. Mon
D. PDT
Answer» E.
11.

What is the output of this program?Note: The program is executed at 3 hour 55 minutes and 4 sec on Monday, 15 July(24 hours time).

A. Mon Jul 15 2013
B. Jul 15 2013
C. 55:03:04 Mon Jul 15 2013
D. 03:55:04 Jul 15 2013
Answer» B. Jul 15 2013
12.

What is the output of this program?Note : The program is executed at 3 hour 55 minutes and 4 sec (24 hours time).

A. 3:55:4
B. 3.55.4
C. 55:03:04
D. 03:55:04
Answer» D. 03:55:04
13.

Which of the following is good coding practice to determine oddity?

A. i
B. ii
C. option (i) causes compilation error
D. option (ii) causes compilation error
Answer» C. option (i) causes compilation error
14.

What one of the following is best practice to handle Null Pointer exception?i) int noOfStudents = line.listStudents().count;ii) int noOfStudents = getCountOfStudents(line);

A. Option (i)
B. Option (ii)
C. Compilation Error
D. Option (ii) gives incorrect result
Answer» C. Compilation Error
15.

Which of the following allows us to call generic methods as a normal method?

A. Type Interface
B. Interface
C. Inner class
D. All of the mentioned
Answer» B. Interface
16.

What will be the output of the following Java program?

A. The snippet compiles, runs and prints 0
B. The snippet compiles, runs and prints 1
C. The snippet does not compile
D. The snippet compiles and runs but does not print anything
Answer» E.
17.

Which tab is used to pass command line argument in eclipse?

A. Arguments
B. Variable
C. both a and b
D. None of the above
Answer» B. Variable
18.

What will be the output of the following Java program, Command line exceution is done as java Output This is a command Line?

A. java
B. this
C. is
D. command
Answer» E.
19.

Is design pattern a logical concept.

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

Which of the following matches end of the string using regular expression in java?

A. \z
B. \\
C. \*
D. \Z
Answer» B. \\
21.

Which of these formatting strings of SimpleDateFormat class is used to print week of the year?

A. w
B. W
C. s
D. S
Answer» B. W
22.

What does SAM stand for in the context of Functional Interface?

A. Single Ambivalue Method
B. Single Abstract Method
C. Simple Active Markup
D. Simple Abstract Markup
Answer» C. Simple Active Markup
23.

Which three statements are true?1. Assertion checking is typically enabled when a program is deployed.2. It is never appropriate to write code to handle failure of an assert statement.3. Assertion checking is typically enabled during program development and testing.4. Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.5. Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.

A. 1, 2 and 4
B. 2, 3 and 5
C. 3, 4 and 5
D. 1, 2 and 5
Answer» C. 3, 4 and 5
24.

___________ is a very small Java framework that makes it trivial to parse command line parameters.

A. Command Line
B. Jcommander
C. Args
D. None of the above
Answer» C. Args
25.

How can junits be implemented using maven?

A. <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> </dependency>
B. <dependency> <groupId>org.junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> </dependency>
C. <dependency> <groupId>mock.junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> </dependency>
D. <dependency> <groupId>junits</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> </dependency>
Answer» B. <dependency> <groupId>org.junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> </dependency>
26.

args in an array of String.

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