Infosys Certified Java SE 21 Developer
Practice with real exam-pattern questions for Infosys Certified Java SE 21 Developer. Each question includes a detailed explanation to help you understand the concept, not just memorise the answer. Try 10 questions free — no login required.
Full question bank for this exam + 1,357+ others. Cancel anytime.
Join Premium10 Infosys Certified Java SE 21 Developer practice questions with answers
Real Lex exam-pattern multiple-choice questions for the Infosys Certified Java SE 21 Developer certification. Each question includes the correct answer. The full question bank is available to Premium members.
- Question 1
Consider the statements with respect to the classes mentioned in the permit classes and choose the correct option?
a) Permitted subclasses must be accessible by the sealed class at compile time.
b) Permitted subclasses must directly extend the sealed class.
c) Permitted subclasses must be in the same module as the sealed class (if the sealed class is in a named module) or in the same package (if the sealed class is in the unnamed module)
d) Permitted subclasses must have exactly one of the following modifiers( final, sealed, nonsealed) to describe how it continues the sealing initiated by its superclass
- ✓
Only options a, b, d are correct
Correct - B
Only options b, c, d are correct
- C
Only options a, c, d are correct
- D
All options are correct
- ✓
- Question 2
In a pattern matching statement with instanceof, what is the role of a pattern variable?
- ✓
It defines a new class for the object being matched.
Correct - B
It stores the result of the instanceof check (true or false).
- C
It holds the value of the object if the type matches the pattern.
- D
It allows for custom logic to be applied during the type check.
- ✓
- Question 3
Consider the following code snippet. Assume all imports are done and preview feature is enabled. Predict the output
int x = 50; int y = 30; StringTemplate st = StringTemplate.RAW."\{x} + \{y} = \{x - y}"; System.out.println(st.fragments()); //Line1 System.out.println(st.values());- ✓
Compilation error at Line1- undefined fragments() method.
Correct - B
[, + , = , ]
[50, 30, 20]
- C
[, + , = , ]
[x, y, x-y]
- D
[, + , = , -, ]
[50, 30, 20]
- ✓
- Question 4
You have a StringTemplate with the following definition:
"Hello, $name! Your favorite color is $color and you are $age years old."
Which of the following code snippets will correctly format the template with the provided data?
- ✓
StringTemplate st = new StringTemplate("Hello, $name! Your favorite color is $color and you are $age years old.");
Correct
String name = "Alice";
String color = "Blue";
int age = 30;
st.name = name;
st.color = color;
st.age = age;
String output = st.toString();
System.out.println(output);
- B
StringTemplate st = new StringTemplate("Hello, $name! Your favorite color is $color and you are $age years old.");
String name = "Alice";
String color = "Blue";
int age = 30;
st.setAttribute("name", name);
st.setAttribute("color", color);
st.setAttribute("age", age);
String output = st.toString();
System.out.println(output);
- C
StringTemplate st = new StringTemplate("Hello, #name! Your favorite color is #color and you are #age years old.");
String name = "Alice";
String color = "Blue";
int age = 30;
String output = st.toString();
System.out.println(output);
- D
StringTemplate st = new StringTemplate("Hello, $name! Your favorite color is $color and you are $age years old.");
String output = st.toString();
System.out.println(output);
- ✓
- Question 5
Given:
void getValue(Object value) { if (!(value instanceof Integer input)) System.out.print("Integer!"); else if (!(value instanceof String input)) { // Line 1 throw new RuntimeException(); } System.out.print("String!"); }What is the output produced on calling getValue("integer")? (Assume the code is present inside in a valid class.)
- ✓
Integer!
Correct - B
Integer! followed by an exception.
- C
Pattern matching with an if statement is implemented using the instanceof operator.
- D
Integer! String!
- E
String!
- ✓
- Question 6
Which of the following is not a Permanent Feature introduced in Java SE 21?
- ✓
Scoped values
Correct - B
Sequenced Collections
- C
Pattern matching for switch
- D
Record patterns
- ✓
- Question 7
Which class in Java provides an implementation of an Enhanced PseudoRandom Number Generator (EPRNG)?
- ✓
java.util.Random
Correct - B
java.util.concurrent.ThreadLocalRandom
- C
java.math.Math
- D
java.security.SecureRandom
- ✓
- Question 8
Assuming that the below code is present in a valid main() method, find the output of the code:
Object obj = "10"; switch (obj) { case Integer i -> System.out.println(i + 5); case String s -> System.out.println(s + "5"); case Long l -> System.out.println(l + 5); default -> System.out.println("Unknown"); }- ✓
15
Correct - B
105
- C
15L
- D
Unknown
- ✓
- Question 9
How does inheritance work with record classes?
- ✓
All record classes inherit from a common base record class.
Correct - B
Record classes can only inherit from other record classes.
- C
Record classes inherit from the Object class by default.
- D
Inheritance behavior for record classes is the same as for regular classes.
- ✓
- Question 10
Choose the correct option for the below statement:
The permits clause in record classes allows:
- ✓
Specifying a set of interfaces that the record class implements.
Correct - B
Controlling access to the record class's constructor(s).
- C
Defining a whitelist of subclasses that can extend the record class.
- D
Associating the record class with a specific type hierarchy.
- ✓
Pay once. Clear every cert this year.
One subscription, full Telegram channel access, every PDF posted during your membership.
- Full access to all 1,357+ certifications
- Monthly updated question banks
- Telegram private channel access
- Cancel anytime
- Everything in Monthly
- Save ₹2,100 vs monthly billing
- Priority answer key requests
- Best for increasing DQ score fast
- Everything in Quarterly
- Lifetime channel access — no renewals
- All future certifications included
- Priority response from admin team
Common questions, straight answers.
A monthly-updated Telegram channel where we post real exam-pattern question banks and detailed answer keys for 1,357+ Infosys Lex certifications. You join once, you get every PDF posted during your membership.
Right after payment on our Graphy page, you'll receive a private invite link to the Telegram channel. Access is instant — usually under 30 seconds.
We compile question banks from the actual Lex test pattern, sourced and verified by 180K+ community members who've recently cleared these exams. Match rate is consistently 85–95%.
Every single month. When Infosys rolls out new versions of certifications, we post updated dumps within 7–10 days. You'll see channel activity weekly.
Clearing certifications is one of the highest-weighted DQ factors. Members typically clear 3–5 certifications in their first 3 months, which moves DQ scores up by a full band.