I think that in this case the constructor is declared, to show us new Java developers, the constructor, so we can start getting familiar with constructors and what the are. It is true that a no argument empty constructor is created by default if one is not specified. It is nice that a default is created so we do not have to do so in every class. If we want to override the constructor and create our own constructor(s) with arguments, this is where the power of constructors comes in. I understand that the location of the constructor is important. When we declare one or more constructors we should declare and empty argument constructor. It is interesting to understand the difference between the constructor and a method in relation to the creation of objects. Checked exceptions can be thrown by the constructor. I'm sure there is more about constructors. This is what I have learned so far.
Keith ________________________________ From: Anton Shaykin <[email protected]> To: Free Java Programming Online Training Course By Sang Shin <[email protected]> Sent: Wednesday, February 25, 2009 11:04:23 AM Subject: [java programming] Re: Why creating empty instances within every class? 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 -~----------~----~----~----~------~----~------~--~---
