Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Harnessing the Power of Objects Incrementing and Decrementing

Default Value mean?

Hello.

What is a default value and what it purpose please?

2 Answers

if no value is provided then the default value is assumed.

if I call a default class constructor

public foo(){ this.x = 1 this y = 2 }

I am providing default values when the class is instantiated

on the other hand. if I call in an overloaded constructor

public foo(x, y){ this.x = x this y = y }

then the default values are ignored.

so the default value it like the default constructor?

if you instantiate an object from a class, and your class has no default constructor, the compiler will make one for you.

I would not this expression "so the default value it like the default constructor?" to describe a default constructor, ..... but in the context of using a default something if you don't provide one ... this may be ok

The bottom line is constructors. (default an overloaded ones). allows you a way to instantiate your object attributes when you create the object.

The default constructor is special because you can provide default values for desired, selected ...etc object attributes that can be used instead of nulls, zeros, blanks ... and so on.

Oh Thank you very much! :)