Thanks guys for sharing your thoughts. Question to [email protected]: What you're saying that in your case a use of default constructor, provided by compiler, is illegal? Is that correct? I think it always works, even if I don't declare any constructors at all (and I'm not saying that it's a good style, it's just one of possibilities (however I guess it makes more sense to declare a constructor in a way like this: public Student() { name = ""; sGrade = 0; mGrade = 0; eGrade = 0; } then just a constructor with empty body. But I might be wrong. Please comment this situation.)) And another small question: in given example, why did you use the "this" keyword? I think you could easily leave it out, could you? Thanks.
On Feb 25, 10:36 pm, [email protected] wrote: > 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 -~----------~----~----~----~------~----~------~--~---
