如图所示,报错原因是啥?Class 'ListNode' is public, should be declared in a file named 'ListNode.java'
我的文件是.java后缀啊

完整代码:
package title.反转链表206;
public class ListNode {
int val;
ListNode next;
ListNode() {};
ListNode(int val) {this.val = val;};
ListNode(int val, ListNode next) {this.val = val; this.next = next;};
}
public class test {
public static void main(String[] args) {
ListNode ans = new ListNode();
ListNode head = CreateList();
ans = new Solution().reverseList(ListNode head);
}
static ListNode CreateList() {
ListNode head = new ListNode();
for (int i = 0; i < 10; i++) {
head = new ListNode(i, head);
}
return head;
}
}
//法1:模拟
class Solution {
public ListNode reverseList(ListNode head) {
ListNode ans = new ListNode();
ans.next = null;
for (ListNode p = head; p != null; p = p.next) {
ans = new ListNode(p.val, ans);
}
return ans;
}
}