Java: Class

This entry is part 20 of 54 in the series Learn Java

A class is a template used to create objects. They are made up of members, the main two of which are fields and methods. Fields are variables that hold the state of the object, while methods define what the object can do.

An object is also called an instance. The object will contain its own set of fields, which can hold values that are different to those of other instances of the class.

package javaapplication19;

public class JavaApplication19 {

    static class MyRectangle {

        int x, y;

        int getArea() {
            return x * y;

    public static void main(String[] args) {
        MyRectangle r = new MyRectangle();      
        int area = r.getArea();


Series Navigation<< Java: Method overloading
Java: Object creation >>

Leave a comment

Leave a Reply