Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method println(boolean) in the type PrintStream is not applicable for the arguments (void)

Tags:

java

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)
like image 605
Clara Singh Avatar asked Jan 30 '26 12:01

Clara Singh


2 Answers

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();
    }

}
like image 64
skl Avatar answered Feb 02 '26 04:02

skl


Println() function expect something while your method doesn't return anything. That's why you are getting error.

like image 45
Aman Goyal Avatar answered Feb 02 '26 03:02

Aman Goyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!