Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Harnessing the Power of Objects Incrementing and Decrementing

Default Value mean?


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! :)