Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

Can someone explain to me what the difference between a setter and constructor is? and If this code looks right? public class Square { // private instance veriable private double length; // constructor public Square(double l) { length = l; } // setter public void setLength(double length) { this.length = length; }

OpenStudy (e.mccormick):

A constructor has the same name as the class and builds things as soon as the class is turned into an object. A setter allows access to the private internals of an object. I saw a great example recently, let me see if I can find/remember where. I think I know, and if I am right, it will show how they are different, but a constructor can use a setter!

OpenStudy (e.mccormick):

This is an example with Java, but it shows how overloaded constructors work. The constrictors are linked to a setter. The rules are similar no matter what the language. The specifics of how to build a constructor are all that really change. Do you use __SELF__ and so on.... http://thenewboston.org/watch.php?cat=31&number=39

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!