Thank you for your answers, guys. I appreciate it. I guess my
'problem' is solved :)
As about that use of "this", you're talking about variable hiding,
like
this.weight = weight;
And I do understand it, but in the given example, like
public Student(String s){
                  this.setStudent(s);
           }
I guess we can omit "this", can we? This is not the case of "variable
hiding". So we can just rewrite this code as:
public Student(String s){
                  setStudent(s);
           }
can we? Thanks for taking your time, to clarify these little things
for me!

On Feb 26, 11:39 am, [email protected] wrote:
> Hi Anton,
>
> As told by other our colleagues of this course, the main objective is TO
> TEACH US A PROGRAMMING STYLE. This means that, at this level of learning,
> you have not to be interested to hide a constructor or to use a default
> constructor. Yes, it's possible to use it and also it is possible to do many
> things that are not explained here, derived by C/C++ programming language!
> On the other hand, we are here to learn in which position to put attributes,
> constructors and methods in a class.
> It doesn't matter that the constructor they're using is EMPTY, the most
> important thing is the position (where to put it inside our class). They're
> a teaching you a style of programming. Why a style? Because YOUR PROGRAMS
> HAVE TO BE UNDERSTOOD BY OTHER PROGRAMMERS so it is really important to be
> clear enough, to put comments where is necessary and so on...
> About your question on "this" keyword...You can observe that they are using
> the same name for the parameters of a method and for the attributes of a
> class! So, to be more clear, it is a practice to use this.attributeName as
> left value in an assignment within a setter/getter method.
>
> this.attributeName = attributeName;
>
> In this way it's enough clear that what you have on your left is the class
> attribute and what you have on your right is the parameter! I hope you
> solved your "problems" ;-)
>
> Mike
>
> P.S.:
> There are a lot of programming style, maybe you're more interested to an
> obfuscated style of programming. :-))
> It depends from what are your objectives! If you're interested to have a
> working program but not readable from other programmers, consider to give a
> look to this website:
>
> http://www.cise.ufl.edu/~manuel/obfuscate/obfuscate.html
>
>         --------- Original Message --------
>
>         Da: [email protected]
>         To: Free Java Programming Online Training Course By Sang Shin
> <[email protected]>
>         Oggetto: [java programming] Re: Why creating empty instances within 
> every
> class?
>         Data: 26/02/09 03:59
>
> > 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.
>
>  --
>  Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP
> autenticato? GRATIS solo con Email.it:http://www.email.it/f
>
>  Sponsor:
>  Incontri con Meetic : Primo sito d'incontri in Europa - Milioni di single !
>  Clicca qui:http://adv.email.it/cgi-bin/foclick.cgi?mid=8293&d=20090226
>
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to