Kevin_Coors
asked on
Java Constructor and Getter and Setter Methods
Hello
I have a quick question regarding Java Constructor and Getter and Setter Methods.
Do you have to declare and initialize both a constructor and getter and setter methods in your class. Or can you choose one or the other?
Thanks
I have a quick question regarding Java Constructor and Getter and Setter Methods.
Do you have to declare and initialize both a constructor and getter and setter methods in your class. Or can you choose one or the other?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but I have read that this is poor practice for encapsulation.Depends who you ask I reckon. Dot notational access implies leaving the back door open for anyone who wants a cup of sugar. Getter method will pass you the sugar through a hatch.
See this.
ASKER
great website!
thanks again
thanks again
Cool.
ASKER
Sorry, If the class variables are private I mean.
I know how to use the dot notation to call a class variable i.e. var.name = "John" but I have read that this is poor practice for encapsulation.
Does Encapsulation require a constructor followed by getter and setter methods?