Purchase Solution

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

Not what you're looking for?

Ask Custom Question

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.

Purchase this Solution

Solution Summary

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

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.