34.2.2 A method which returns a reference-type variable

28 views
Skip to first unread message

meon.a...@gmail.com

unread,
Jan 11, 2015, 2:12:37 PM1/11/15
to moo...@googlegroups.com
Hi,

I'm having problems with week 7 exercise _.-- section 34.2.2

What is the difference between a constructor that creates an Calculator object and the method createCalculator?

public Calculator createCalculator(int startValue) {
    return new Calculator(startValue);
}


Best regards,
Meon

Joni

unread,
Jan 15, 2015, 2:22:40 AM1/15/15
to moo...@googlegroups.com, meon.a...@gmail.com
Hi,

The new Calculator statement is calling the Calculator class constructor.
Sure they are different but it could have been written as 

Calculator bonus  = new Calculator(10);
Calculator lennon = new Calculator(10);

That example is stupid in a way and I suggest that you don't use that in your own code.

BR
Joni 
Reply all
Reply to author
Forward
0 new messages