In the following code when I take the name of the reference same while calling both the constructors i get an error stating "c is already defined in main(java.lang.String)".But when I change the name of one of the references I get no errors.Why is it so?
A type (cont) followed by a variable name (c) is the syntax for declaring a variable. So when you say "cont c" a second time, Java thinks you're trying to declare a second variable with the same name as the first.
If you want to use the same c after declaring it, just use the variable name without the type...
cont c = new cont(); //declaration (and assignment) c = new cont(6); //reassignment
If you want a different variable, then provide the type for the new variable...
cont c = new cont(); cont d = new cont(6);
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Feb 16, 2006
I am still confused What I have learned is that on writing:
we create a memory space for an object of cont type,and when we write:
we create a reference to the memory allocated to the object. Then when we write:
What is actually happening and why? [ March 20, 2006: Message edited by: Samarth Barthwal ]