xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to create a class and its object in Java
Java Online Editor
Execute Code
More Java Sample Codes
public class ExampleApp { public static void main(String[] args) { Person personObj = new Person(); // personObj is the object of the Person class // Note: You can create class objects as many as you need with unique variable names personObj.setName("John"); // assign value to class property personObj.setAge(25); // assign value to class property System.out.println(personObj.getName() + " is " + personObj.getAge() + " years old."); // writing return value } } // This is a class class Person { private String name; private int age; // Getter and setter methods for name property public String getName() { return name; } public void setName(String name) { this.name = name; } // Getter and setter methods for age property public int getAge() { return age; } public void setAge(int age) { this.age = age; } }