当我尝试执行以下代码时出现错误:
package Abc;
public class Class3 {
public void another() {
System.out.println("Hello World");
}
public static void main(String[] args) {
Class3 obj1 = new Class3();
System.out.println(obj1.another());
}
}
错误是:
The method println(boolean) in the type PrintStream is not applicable for the arguments (void)
最佳答案
您的 another() 函数返回类型为“void”,这实际上表示它被定义为不返回任何内容。
package Abc;
public class Class3 {
public void another() {
System.out.println("Hello World");
}
public static void main(String[] args) {
Class3 obj1 = new Class3();
obj1.another();
}
}
关于java - PrintStream 类型中的方法 println(boolean) 不适用于参数 (void),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43436261/