I've learned C# over the course of the past six months or so and am now delving into Java. My question is about instance creation (in either language, really) and it's more of: I wonder why they did it that way. Take this example
Person Bob = new Person();
Is there a reason that the object is specified twice? Would there ever be a something_else Bob = new Person()?
It would seem if I were following on from convention it would be more like:
int XIsAnInt;
Person BobIsAPerson;
Or perhaps one of these:
Person() Bob;
new Person Bob;
new Person() Bob;
Bob = new Person();
I suppose I'm curious if there's a better answer than "that's just the way it is done".
LivingThing? You could writeLivingThing lt = new Person(). Look for inheritance and interfaces. – xlecoustillier Feb 07 '15 at 19:55Person Bobdeclares a variable of type "reference toPerson" calledBob.new Person()creates aPersonobject. References, variables and objects are three different things! – user253751 Feb 08 '15 at 01:48Person Bob = new Person()isdim Bob As Person = new Personbut can also dodim Bob As new Person()which combines two stages. – user1937198 Feb 08 '15 at 12:25var bob = new Person();? – 200_success Feb 08 '15 at 18:19Person Bob();is possible in C++ and means nearly the same thing asPerson Bob = Person();– flaviut Feb 08 '15 at 18:34Person Bob(1);would be correct though. – flaviut Feb 10 '15 at 00:08