Multiple choice technology programming languages

Given: 10. class Line { 11. public class Point { public int x,y; } 12. public Point getPoint() { return new Point(); } 13. } 14. class Triangle { 15. public Triangle() { 16. // insert code here 17. } 18. } Which code, inserted at line 16, correctly retrieves a local instance of a Point object?

  1. Point p = Line.getPoint();

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

  3. Point p = (new Line()).getPoint();

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

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Point is an inner class of Line, so it must be accessed as Line.Point from outside the enclosing class. The getPoint() method is an instance method requiring a Line object to invoke. Option D correctly creates a Line instance, calls its getPoint() method, and uses the proper inner class syntax for the variable declaration.