Java Classes
Java Classes
C LA SS ES
Classes:W TF IS IT?!
Okay, so youre probably referring to
apple pie)
You need the recipe in order to make
the apple pie, but the recipe doesnt
make it for you (you need to make it
yourself)
Classes makes objects
Apple pie recipe makes apple pie
H ow To KillA M ockingbird
M ake Apple Pie
So, what is needed in a class?
Classes consist of two major parts:
Properties / attributes
Methods
H ow To KillA M ockingbird
M ake Apple Pie
Lets use the apple pie again =D (cause I
up a class
The properties are the arguments that
Constructing a Constructor
Defined by public className (args)
Can have no args (known as the default)
Can have as many arguments as you
H O LD U P! W H AT TH E H ECK IS
TH IS(.)?!
Okay, before we continue, I feel this is the
AN YW AYS
Now that we have a constructor set
Continuing O n
Sets = setting a variable to equal
something
Sir, my apple pie has two cups of sugar,
already there
type
public int getDiameter()
Is int because I want the diameter, which
is an int
be so picky about
ALWAYS)
This is because you only want to set the
Easy right?
BUT WAIT!
Now that we know exactly how to
give everyone
public int howMuchPie(int pieces)
{
totalArea = //some equation to figure out
//area of pie
return totalArea / pieces;
}
object
Take Scanner for example
How do you use scanner?
Scanner input = new Scanner
(System.in);
Then
We just write stuff to test and make sure
acceptable
This is just to say Hey! This class works
correctly
regular program
Few things
Normally, you SHOULD check for
ANY QUESTIONS?
TH E EN D