0

I've written two files (Node.java and priorityQueue.java) that are in the same directory, and I'm trying to use Node inside priorityQueue by using "extends".

However, I'm getting "error: cannot find symbol" wherever "Node" appears in my priorityQueue.java file.

Node.java:

public class Node {
  private int priority;
  private String name;
  public Node(int priority, String name) {
    this.priority = priority;
    this.name = name;
  }
  // some methods ...
}

priorityQueue.java:

import java.util.ArrayList;

public class priorityQueue extends Node {
  public ArrayList<Node> pq = new ArrayList<Node>();
  // some methods ...
  public static void main(String[] args) {
    priorityQueue p = new priorityQueue();
    Node a = new Node(10, "a");
    p.enqueue(a);
    System.out.println(p.dequeue().getName());
  }
}

This is the first error message:

priorityQueue.java:4: error: cannot find symbol
    public ArrayList<Node> pq = new ArrayList<Node>();
                     ^

I'm more used to c++ and c using imports, but I've been told that extends should work without importing anything as long as the files are in the same directory. What am I missing?

I'm on windows 10, java 14.0.1, and using notepad++ as an IDE.

Otherness
  • 385
  • 2
  • 16
  • 2
    How are you trying to compile those classes? Via console? If yes how your command looks like? From which location is it called? – Pshemo Jun 23 '20 at 22:56
  • SOLUTION: It turns out there were two problems: I wasn't compiling properly and I needed to remove "extends Node". – Otherness Jun 23 '20 at 23:53

1 Answers1

1

do you want use priority queue based on node ? if it is as i expect u shouldn't extends the class Node but u will create an Node's object through the Priority Queue class

chu3la
  • 18
  • 5