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.Person Bob
declares a variable of type "reference toPerson
" calledBob
.new Person()
creates aPerson
object. References, variables and objects are three different things!var bob = new Person();
?Person Bob();
is possible in C++ and means nearly the same thing asPerson Bob = Person();