• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default constructor..

 
Marcos Vilela
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Constructor with no arguments will be the default constructor?

Answer: False..


Why not?

Thanks..
 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can not define any default constructor.Default constructor genrated by JVM when there is no any constructor..is defined in the program.
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLS 8.8.7 holds all the answers to this question.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic