1. Given: 10. class Line { 11. public static class Point { } 12. } 13. 14. class Triangle { 15. // insert code here 16. } Which code, inserted at line 15, creates an instance of the Point class defined in Line?
  1. Point p = new Point();

  2. Line.Point p = new Line.Point();

  3. The Point class cannot be instatiated at line 15.

  4. Line 1 = new Line() ; 1.Point p = new 1.Point();


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Point p = new Point(); This option is incorrect because it tries to create an instance of the Point class without specifying the enclosing class.

Option B) Line.Point p = new Line.Point(); This option is correct because it correctly specifies the enclosing class (Line) and creates an instance of the Point class defined within it.

Option C) The Point class cannot be instantiated at line 15. This option is incorrect because the Point class can be instantiated, as shown in option B.

Option D) Line 1 = new Line() ; 1.Point p = new 1.Point(); This option is incorrect because it has a syntax error. The variable name "1" is not a valid identifier.

The correct answer is B. This option is correct because it correctly creates an instance of the Point class defined within the Line class.

Find more quizzes: