nerdexam
GIAC

GSSP-JAVA · Question #26

You work as a Programmer for InfoTech Inc. You write the following code. 1. public class InnerDemo{ 2. public static void main(String[] args) { 3. Car c = new Car(); 4. // insert code here 5…

The correct answer is A. Car.Engine e = c.new Engine(). See the full explanation below for the reasoning.

Question

You work as a Programmer for InfoTech Inc. You write the following code. 1. public class InnerDemo{ 2. public static void main(String[] args) { 3. Car c = new Car(); 4. // insert code here 5. e.test(); 6. } 7. } 8. class Car{ 9. class Engine{ 10. void test() {System.out.println("test"); } 11. } 12. } Which of the following options should you add to line 4 so that the code compiles and produces the output "test"?

Options

  • ACar.Engine e = c.new Engine();
  • BEngine e = c. new Engine();
  • Cc.Engine e = Car.new Engine();
  • DCar.Engine e = Car.new Engine();

How the community answered

(32 responses)
  • A
    78% (25)
  • B
    3% (1)
  • C
    13% (4)
  • D
    6% (2)

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice