Results 1 to 3 of 3
Thread: why can't I use new?
- 12-23-2009, 07:53 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 6
- Rep Power
- 0
why can't I use new?
Hi guys
I've just started Java and I don't know much and do not have much experience either. Anyway, I was practising, and I wrote the following script:
My file was named example.javaJava Code:class printstr{ void printstr(String var) { System.out.println("String argument: " + var); } } class example{ public static void main(String args[]) { printstr obj1 = new printstr("example string"); } }
Somehow my java compiler gave an error saying:
Initially I thought there was something wrong with my code. So I copied some code from the book I was learning java from which contained the keyword new, and my javac gave the same error.Java Code:C:\java>javac say.java example.java:9: cannot find symbol symbol : constructor printstr(java.lang.String) location: class printstr printstr obj1 = new printstr("example string"); ^ 1 error
Is there something wrong with my compiler? I have the latest version of it - JDK SE 6 Update 17. Or is java2 too old or someting, because I'm learning Java2..
Please help!Last edited by tehhparadox; 12-23-2009 at 07:56 PM.
-
Nope, it's your code. What you think is a constructor isn't because you have a "void" return type assigned to it. Constructors have no return type at all.Is there something wrong with my compiler?
- 12-23-2009, 08:41 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 6
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks