What are the benefits of using the public variable version


Discuss teh below:

Q: 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; }
}

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

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

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

Solution Preview :

Prepared by a verified Expert
JAVA Programming: What are the benefits of using the public variable version
Reference No:- TGS01934706

Now Priced at $25 (50% Discount)

Recommended (94%)

Rated (4.6/5)