. Java . Java Basics

Java Basics

classes, objects, variables, and methods

class
A grouping of "variables" and "methods".
In the example below, Cat (line 1) is a class.

object
An "instance" or of a class. Below (line 14) we create a Cat named patches.

variable
Data stored in the class with a given name.
Below (line 2 & 3) we have the variables animalType and animalColor.

method
A grouping of java code with a name, list of zero to n variables in, and zero or one variables out.
Below (line 8) getCatsColor is a method.
1 class Cat {
2     private String animalType = "feline";
3     private String catColor;
4     Cat(String colorIn)
5     {
6         catColor = colorIn;    
7     }
8     public String getCatsColor()
9     {
10        return catColor;  
11    }
12    
13    public static void main (String[] argsIn) {
14        Cat patches = new Cat("calico");
15    }
16 }
Comments Comments are left by visitors to FluffyCat.com, are not endorsed by FluffyCat.com, and may or may not be accurate.
Comment by simham Rate this Comment

How to Write test Cases for Servlets using Junit in eclipse

Sign In
to add your own comment