Explore BrainMass
Share

Explore BrainMass

    3 Questions on Java !!! public variable or bean-style access

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Suppose that you need a FullName class, which will contain a person's first name and last name. There are two different ways of implementing this.

    A. The public variable version:

    class FullName
    {
    public String first;
    public String last;
    }

    B. The bean-style accessor version:

    class FullName
    {
    private String first;
    private String last;

    public String getFirst() { return first; }
    public void setFirst(String s) { first = s; }

    public String getLast() { return last; }
    public void setLast(String s) { last = s; }
    }

    Questions:

    1. What are the benefits of using the public variable version?

    2. What are the benefits of using the bean-style accessor version?

    3. Add a constructor to your preferred version, that takes two String parameters and initializes first and last.

    © BrainMass Inc. brainmass.com October 10, 2019, 12:28 am ad1c9bdddf
    https://brainmass.com/computer-science/java/3-questions-on-java-public-variable-or-bean-style-access-293228

    Solution Summary

    The answers are given complete step by step and in an easy to understand manner. Grab the solution and enjoy the learning.

    $2.19