wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Default constructor.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Default constructor.." Watch "Default constructor.." New topic

Default constructor..

Marcos Vilela

Joined: Jul 06, 2005
Posts: 18
A Constructor with no arguments will be the default constructor?

Answer: False..

Why not?

Bk Jacky
Ranch Hand

Joined: Jun 11, 2005
Posts: 74
we can not define any default constructor.Default constructor genrated by JVM when there is no any constructor..is defined in the program.

SCJP1.4<br />SCWCD1.5<br />"Nothing is impossible"
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
the answer is false because it is not neccessarily the default constructor. The default constructor is the one the compiler provides.

so meaning that, such as:
class Employee{
Employee() // explicitly type constructor with no-arg, this one is not provided by compiler.
// do code
class Employee{
// you do not type the constructor out, so the compiler will provide you a default constructer, which is Employee(){}

if not understand by my code, go to page 316 on K&B book.

all the best

From NickyEng
Diploma in Computer Studies
SCJP 1.4
Formula 1 app by Maxis (Playbook)
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Here's a quick example...

How is that constructor different from the default constructor that would have been provided had I not written a constructor of my own? The one I wrote has no arguments, but it's definitely different from the default that would have been provided. Can you see how?

SCJP Tipline, etc.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
JLS 8.8.7 holds all the answers to this question.

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link: http://aspose.com/file-tools
subject: Default constructor..
It's not a secret anymore!