JAVATM- The Beginnings

Classes

Section 1 - Classes Defined

A class is a user-defined type. It is a programming construct that enhances data by

defining methods that operate on them.

Consider the following int primitive:

int number = 12;

What if we needed to constrain the value of the int primitive to be less than 7. We would

have to write extra code to enforce the constraint.

int number = 7;

if (number > 6)

{

    number = 6;

}

This would have to be repeated for each number.

int number = 7;

if (number > 6)

{

    number = 6;

}

int number2 = 13;  

if (number2 > 6)

{

    number2 = 6;

}

It's very easy to make a mistake.

int number = 7;

if (number > 6)

{

Copyright ©2017 by Ralph Lecessi Incorporated. All rights reserved.



Back to ralphlecessi.com