public class Example {
static void sayHello() {
System.out.println("Hello!");
}
public static void main(String[] args) {
sayHello().<span style="color:red">toString()</span>;
}
}
Error:
Reason for the error:
As you can see we get an error "void cannot be dereferenced" when we try to access a member on a void type. In the above example sayHello() returns void and we are trying to access toString()
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!