Results 1 to 6 of 6
Thread: Can't find symbol. Constructor
- 08-02-2012, 05:33 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
Can't find symbol. Constructor
Hello pros :)
I'm trying to implement a simple program which uses a constructor.
Here's my code:
Here' my error:add_cons.java:28: cannot find symbolJava Code:import java.io.*; class add { private int c; void add(int a, int b) { c = a + b; } void display() { System.out.println("Result is " +c); } } class Mainn { public static void main(String args[]) throws IOException { int x, y; BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter 2 numbers: "); x = Integer.parseInt(obj.readLine()); y = Integer.parseInt(obj.readLine()); add o = new add(x, y); o.display(); } }
symbol : constructor add(int,int)
location: class add
add o = new add(x, y);
^
1 error
I'm using Ubuntu. Java 1.7
Thanks,
Sid
- 08-02-2012, 05:42 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Can't find symbol. Constructor
A constructor doesn't have a return value in its signature...that includes 'void'.
so not:
void add(int x, int y) {etc.}
but
add(int x, int y) {etc.}Please do not ask for code as refusal often offends.
- 08-02-2012, 05:46 PM #3
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Can't find symbol. Constructor
You don't have a constructor with 2 int arguments. I'm assuming that you think this is a constructor:
...but that is actually just a method. A definition of a constructor uses the syntax: public className(type arg0, type arg1, type arg2, ....)
If I wasn't clear enough, check out this tutorial: Constructors"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-02-2012, 05:47 PM #4
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Can't find symbol. Constructor
Not fast enough...
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-02-2012, 05:49 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
Re: Can't find symbol. Constructor
Oops. Not even void?! That was pretty noob

Thanks
- 08-02-2012, 05:54 PM #6
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Can't find symbol. Constructor
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
Similar Threads
-
cannot find symbol - constructor Gun()
By 2341234 in forum New To JavaReplies: 3Last Post: 04-02-2012, 09:48 AM -
overridding constructor causes can not find symbol
By bflhr673 in forum New To JavaReplies: 5Last Post: 07-27-2010, 10:36 AM -
cannot find symbol constructor
By daud in forum New To JavaReplies: 9Last Post: 08-13-2009, 03:53 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
Error: cannot find symbol constructor
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 08:24 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks