1

So there's no class extension as in this question, so I'm trying to understand what the super() method call is doing?

I could understand super if the keyword extend was being used as in the referenced SO question, but it is not.

 public class Solver {
   private Node result;

   private class Node implements Comparable<Node> {
     Node prev;
     Board value;
     int moves = 0;
     int priority;
     public Node(Board value, Node previous) {
       super();
       //stuff
       //stuff
     }

     @Override
     public String toString() {
       //stuff
     }

     @Override
     public int compareTo(Node node) {
        //stuff
     }
   }
 }
Community
  • 1
  • 1
Nona
  • 5,302
  • 7
  • 41
  • 79

2 Answers2

1

There is always a super class called Object, so it will invoke constructor of Object.

Rakesh KR
  • 6,357
  • 5
  • 40
  • 55
  • But why call super in Node then? Why not just call it in Solver? I don't understand why you would call the Object constructor in the first place – Nona Mar 02 '16 at 06:14
  • U can go through http://docs.oracle.com/javase/tutorial/java/IandI/super.html – Rakesh KR Mar 02 '16 at 06:31
  • @Nona `Solver` and `Node` are two different classes. The constructor for `Solver` is called when you create a `Solver` object, and the constructor for `Node` is called when you create a `Node` object. If `Node` were a subclass of something interesting, then calling `super()` in `Solver` wouldn't help at all when you create a `Node`. – ajb Mar 02 '16 at 06:32
1

When you do not extends any class then by default the inherited class is Object so it calls Object class constructor.

Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94