+ 2
Can constructors be called as normal methods?
6 odpowiedzi
+ 14
@Morgan No, you can't. You should use setters if you want to do that.
+ 13
Please define 'normal'...
What do you mean? You can call a constructor without storing the returned object if this is what you want to know.
+ 12
Shouldn't it be this.someRandomVariableToBeIncremented += number; ?
+ 1
constructors are meant to initialise an object, but can it be called multiple times instead of recreating another method that does the exact same thing
+ 1
Say, the constructor initialises the object with incrementing a variable passed on to the parenthesis
//main
Foo bar = new Foo(8);
//constructor for class Foo
Foo(int number){
this.someRandomVariableToBeIncremented += number;
}
after initialising this object, i want to add another 5 to the "someRandomVariableToBeIncremented" at that instance
so can i call the constructor again using bar.Foo()?
weird question, kinda dumb but i dont really get this part
+ 1
@110000 yeah sorry, realised that and wanted to change it just now. Its fixed now, thanks for the help everyone ;_______;