File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Error printing on Console !!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Error printing on Console !!!!!" Watch "Error printing on Console !!!!!" New topic
Author

Error printing on Console !!!!!

shankar changayil
Greenhorn

Joined: Jul 26, 2000
Posts: 4
public class Test1{
Test1(){}
void method1()
{
System.out.println("method");
}
public static void main(String args[])
{
Test1 t = new Test1();
//line 12. System.out.println ("printing" + t.method1());
}
}
//Here is my doubt ???
At line 12 I am getting the following error...
Incompatible type for +. Can't convert java.lang.String to in System.out.println ("printing" + t.method1());
Can anyone help with this!!!
Thanks in advance.
AJ Dussault
Ranch Hand

Joined: May 17, 2000
Posts: 53
shankar,
you can do a couple of things:
1.
class Untitled1 {
Untitled1() {}
void method1()
{
System.out.println("method");
}
public static void main(String args[])
{
Untitled1 t = new Untitled1();
System.out.println ("printing");
t.method1();
}
}
OR
2.
class Untitled1 {
String method1()
{
return "method";
}
public static void main(String args[])
{
Untitled1 t = new Untitled1();
System.out.println ("printing" + t.method1());
}
}
Amanda
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
Shankar
The method returns void. You r not returning anything. You r printing to the console instead. How do u expect it to get concatenated within another print statement.
Try changing the void method to String method and return ("xyz"); instead of the print statement. It should work.
Ankur
Uvnik Gupta
Ranch Hand

Joined: Jul 24, 2000
Posts: 32
modify method1() as :
String method1()
{
return ("method");
}

shankar changayil
Greenhorn

Joined: Jul 26, 2000
Posts: 4
Amanda, Gupta and Ankur
thanks for the prompt reply
i had tried the t.method1. it worked with the void return type so i was thinking that it should work the same way in the System.out.println as well. As ankur wrote it is not possible at all to print to the console without the return type.
great!!!
shanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error printing on Console !!!!!