Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

void return type is not allowded HF SCJP

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see Page no28 Chapter 1 [Kathy Sierra]

<code>
package cert;

/**
*
* @author satya
*/


public class Roo
{
public String doRooThings()
{
return "Fun";
}

}


package notcert;
/*
* Main.java
*
* Created on January 14, 2007, 11:19 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import cert.*;




class Cloo extends Roo
{
public void testCloo()
{
// System.out.println(this.testCloo());==> printes error "void type is noy allowded"
this.testCloo(); //now this works fine
}

}

</code>

Q1) Please let me know why "System.out.println(this.testCloo())" is not allowing not print value?
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is because System.out.println() expects either of the "boolean,char,char[] ,double ,float ,int,long,Object,String". Your method testCloo() returns void and hence the compiler error mentions that method returning void can not be used here.

thanks,
amit

P.S: Your subject of the post is confusing.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you are asking yet, but here is some code that will compile.
Please examine this code and clarifiy your question, others will be able to help you then.

To change this template, choose Tools | Template Manager ... ?

What template, from where ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic