LDC: Lower Division Clerk — Role, Skills & Exam Essentials: 18 MCQs with answers
All 18 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 6 questions
Q1. What does the JVM opcode `ldc` stand for?
BeginnerShow answer & explanation
Load Constant
`ldc` expands to **Load Constant**. It is the JVM instruction that fetches a constant from the class's constant pool and pushes it onto the operand stack.
Q2. Where does `ldc` read its value from?
BeginnerShow answer & explanation
The class's constant pool
`ldc` reads from the **constant pool** of the current class. Local variables are read by the `*load` family (`iload`, `aload`, `fload`), and static fields by `getstatic`.
Q3. How many bytes wide is the constant pool index carried by plain `ldc`?
BeginnerShow answer & explanation
1 byte
`ldc` carries a **1-byte unsigned index** (0–255), which keeps the bytecode compact. The 2-byte form is `ldc_w`.
Q4. Which opcode must be used to push a `double` constant?
BeginnerShow answer & explanation
`ldc2_w`
`long` and `double` occupy **two operand-stack slots**, so they require `ldc2_w`. Plain `ldc` handles only single-slot values.
Q5. A compiler emits `ldc #7 // String hello`. What does the `#7` refer to?
BeginnerShow answer & explanation
Entry 7 in the class's constant pool
The number after `ldc` is the **constant pool index**. Entry 7 in this class's pool holds the string `hello`, which `javap` helpfully prints as a comment.
Q6. **ldc** is a JVM bytecode instruction that loads a constant from the class's constant pool onto the operand stack, using a 1-byte index.
BeginnerShow answer & explanation
True
**ldc** is a JVM bytecode instruction that loads a constant from the class's constant pool onto the operand stack, using a 1-byte index.
Building up · 7 questions
Q7. A class's constant pool has grown to 400 entries. Which opcode will the compiler use for a `String` literal?
IntermediateShow answer & explanation
`ldc_w`
A 1-byte index can only address 0–255, so a 400-entry pool needs the **2-byte index** of `ldc_w`. `ldc2_w` is reserved for `long` and `double`.
Q8. Why does the JVM keep literals in a constant pool instead of inlining them in bytecode?
IntermediateShow answer & explanation
It deduplicates literals and allows lazy resolution
The pool **deduplicates** repeated literals — one entry, many `ldc` references — and enables **lazy resolution**, so a class reference is not loaded until an `ldc` actually touches it.
Q9. Which statement correctly contrasts `iload_1` with `ldc 5`?
IntermediateShow answer & explanation
`iload_1` reads a local variable; `ldc 5` pushes a pool constant
The `*load` family reads **local variable slots** in the stack frame, while `ldc` reads the **constant pool**. They share the word "load" but are unrelated mechanisms.
Q10. Which of these constants can plain `ldc` push directly?
IntermediateShow answer & explanation
A `Class` literal such as `String.class`
`ldc` handles single-slot constants including `int`, `float`, `String`, `Class`, `MethodType`, `MethodHandle` and `Dynamic`. `long` and `double` need `ldc2_w`, and local variables need `*load`.
Q11. A student writes `int i = 5;` and `long x = 5L;`. Why do the two statements compile to different constant-loading opcodes?
IntermediateShow answer & explanation
`long` takes two stack slots, so it needs `ldc2_w`
The deciding factor is **operand-stack slot count**: `long` and `double` occupy two slots, so the JVM provides `ldc2_w` for them. Both values still live in the constant pool.
Q12. Which instruction pushes the value of a **static field**, rather than a literal?
IntermediateShow answer & explanation
`getstatic`
`getstatic` reads a **static field's value**. `ldc` and its variants push constants from the pool, and `bipush` pushes a small integer literal inline.
Q13. Why does `System.out.println("Hi");` contain an `ldc` in its bytecode?
IntermediateShow answer & explanation
The string literal `"Hi"` must be pushed from the constant pool
`System.out` is fetched with `getstatic`, but the argument `"Hi"` is a **string literal**, so the compiler emits `ldc` to push it onto the operand stack before `invokevirtual`.
Topper level · 5 questions
Q14. A developer wants to see exactly which constant pool entry each `ldc` uses in a compiled class. Which command is appropriate?
AdvancedShow answer & explanation
`javap -c` on the class file
`javap -c` disassembles the class and prints each `ldc` with its **pool index and a comment** showing the value, e.g. `ldc #7 // String hello`. That is the fastest way to read stack-based execution.
Q15. Consider these statements about the constant pool: I. It is shared globally across all loaded classes. II. Entries are resolved lazily, only when touched. III. Repeated string literals share a single entry. Which are correct?
AdvancedShow answer & explanation
II and III only
The constant pool is **per-class**, not global, so statement I is wrong. Statements II (lazy resolution) and III (deduplication) are both correct.
Q16. A method contains `String.class` and `Class.forName("com.example.Foo")`. What do these two constructs have in common at the bytecode level?
AdvancedShow answer & explanation
Both rely on `ldc` to push a pool entry before resolution
A `Class` literal and the class-name string passed to `Class.forName` are both **constant pool entries**, so `ldc` pushes them before the JVM resolves the class. Neither takes two slots, so `ldc2_w` is not involved.
Q17. A developer is optimizing a Java application with a large constant pool containing over 300 entries. They want to ensure efficient bytecode generation for string literals. Which instruction should they expect to see in the compiled bytecode for a string literal?
AdvancedShow answer & explanation
ldc_w
The correct option is `ldc_w` because it is used for constant pools with more than 255 entries, ensuring that the string literal can be correctly referenced without exceeding the index limit.
Q18. Consider a Java method that includes the following lines of code: `String str = "Hello"; double value = 3.14;`. When compiled, which of the following bytecode instructions will be generated for these lines, and why?
AdvancedShow answer & explanation
The string uses `ldc`, while the double uses `ldc2_w`
The correct option is that the string uses `ldc` because it fits within a single slot, while the double requires `ldc2_w` because it occupies two slots on the operand stack.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages