Multiple choice technology programming languages

Given: 11. public abstract class Shape { 12. int x; 13. int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } and a class Circle that extends and fully implements the Shape class. Which is correct?

  1. Shape s = new Shape(); s.setAnchor(10,10); s.draw();

  2. Circle c = new Shape(); c.setAnchor(10,10); c.draw();

  3. Shape s = new Circle(); s.setAnchor(10,10); s.draw();

  4. Shape s = new Circle(); s->setAnchor(10,10); s->draw();

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

An abstract class cannot be instantiated directly, making option 1 invalid. Option 2 is invalid because you cannot assign a superclass reference to a subclass variable. Option 3 correctly instantiates the concrete subclass Circle and assigns it to the superclass reference Shape.