You are right but the best practice is to declare the constructor
exmplicitly.
for example
public class Student {
// Only one constructor explicitly declared.
public Student(String s){
this.setStudent(s);
}
}
//Now we may instantiate class as follows:
Student s = new Student("123-456");
// but we can not
Student s = new Student();
As java compiler will not produce default constructor this thime. So
as per me its best practice do construct explicitly.
On Feb 26, 5:04 am, Anton Shaykin <[email protected]> wrote:
> I don't know why I got replies to my normal address and can't see any
> posts here, but anyway. You told me that it's a default constructor.
> But isn't default constructor called "default" because it's used by
> compiler without need to declare it? In other words, code is compiled
> and works perfectly well even without declaring default constructor,
> and in this case I think compiler use its own default constructor, so
> we don't need to declare one, do we?
> It's like when you use default access modifier - there's no need to
> specify it by 'default' keyword.
> So my opinion is that use of such a constructor is redundant.
> Does anybody else have different opinion. Please, share it. Thank you.
>
> On Feb 25, 7:50 pm, Anton Shaykin <[email protected]> wrote:
>
>
>
> > Really. Why do we create empty instances for every class, like this:
>
> > public class StudentRecord {
>
> > /** Creates a new instance of StudentRecord */
> > public StudentRecord() {
> > }
>
> > }
>
> > Does it make sense at all? What's the need to do it?
> > Thank you.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---