有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在main中使用时未找到java符号

在我的方法中,我试图在我的main方法中使用一个名为CLB的声明常量。这个常数在另一个叫做Card的类中。当我尝试使用我在主类中编写的setSuit方法时,它会给我“Symbol not found”

我有一门课叫卡片

public class Card {

private char value;
private char suit;
public String card = "";
final int NOC = 52; //number of cards
final int NOF = 4;  //number of faces
final int NOV = 13; //number of values

//SUITS; 3 letter designation
private final char CLB = '\u2663';
private final char SPD = '\u2660';
private final char HRT = '\u2764';
private final char DMN = '\u2666';

//Array of suits and values
public char[] cardSuit = {CLB, SPD, DMN, HRT};
public char[] cardValue = {'A', 'K', 'Q', 'J', 10, 9, 8, 7, 6, 5, 4, 3, 2};    


//CONSTRUCTOR
public Card(){}

public Card(char suit, char value)
{
    this.suit = suit;
    this.value = value;        
}

public void setSuit(char s)
{
    if (contains(cardSuit, s)) 
    {
        suit = s;
    }

这里是主要的

public static void main(String[] args) {
    Card test = new Card();
    test.setSuit(CLB);

我不太确定我做错了什么,因为在我的理解中,对象测试应该包含诉讼


共 (2) 个答案

  1. # 1 楼答案

    声明如下:

    public final static char CLB = '\u2663';
    

    就这样说吧

    Card.CLB 
    
  2. # 2 楼答案

    如果您的main方法位于另一个类中,则需要将CLB公开(public final char CLB = '\u2663';),并像这样引用CLB:Card.CLB