对象和类的Java编码问题

问题描述:

由于某些原因,我无法弄清楚以下内容出了什么问题
java文件.任何帮助将非常感激.我敢肯定,这很简单,我很茫然! :confused:

For some reason I can''t figure out what is wrong with the following
java file. Any help would be really appreciated. I am sure that it is something simple bit I am at a loss! :confused:

class Test {
  public static void main(String[] args) {
  A a = new A();
  a.print();
  }
}





class A {
  String s;

 A(String s){
   this.s = s;
}

public void print() {
  System.out.print(s);
  }
}

try::-D

try : :-D

class Test {
public static void main(String[] args) {
A a = new A("World of Warcraft!");
a.print();
}
}


只是尝试充实" Adrabi的答案:

您创建了A类,其构造函数将单个字符串作为输入.

然后,当您创建新A时,您没有传递任何内容.我假设您应该传递的内容来自参数列表,对吗?

您可能想要:

Just to try to "flesh out" Adrabi''s answer:

You created class A with a constructor that takes as input a single string.

Then, when you created your new A, you didn''t pass anything in. I assume what you were supposed to pass in was from the argument list, correct?

You may have wanted:

public static void main(String[] args) {
    for (String s: args)
    {
        A a = new A(s);
        a.print();
    }  
}


尝试这样的事情

公共课程测试{
公共静态void main(String [] args){
A a = new A();
a.print();
}
}

becoz,Java需要的主类是公共访问说明符
Try some thing like this

public class Test {
public static void main(String[] args) {
A a = new A();
a.print();
}
}

becoz, Java need main class is public access specifier