Logo

Home Basics Structures Collections Constructors and Methods Classes

Constructors and Methods:

Type
Description
Example
Constructor
Every class has a constructor. The constructor initializes the fields of the class. It as the same name as the class and can take parameters. public Test(int number, String name)
{
num = number;
personName = name
x= 7;

}
Accessor Method
Is a method that returns what is in the fields. These methods must have a return type and must return an object of that type. These methods can return a field or can return other types that are not fields of the class. public String getName()
{
return personName;
}
Mutator Methods
Is a method that changes a field. These methods are of type void and can be simple as changing a name or can be as complex as having multiple algorithyms, if-else statements, loops and all sorts of other parts of programming public void set name(String name)
{
personName = name;
}

 

Copyright 2009 Kimberly Pardue
Last updated: March 18, 2009

Home | Basics |Structures |Collections |Con/Meth |Classes