I am getting an error when I try executing the following code:
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 error is:
The method println(boolean) in the type PrintStream is not applicable for the arguments (void)
Your another() function return type is 'void' which essentially says it is defined to return nothing.
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();
}
}
Println() function expect something while your method doesn't return anything. That's why you are getting error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With