Introduction To Java Classes

Classes are the core of java programming. They contain all the methods and syntax of the code for execution.  It forms the basis and structure for the object oriented programming of java language.


A class can be declared by the following. eg:


public class myClass {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// creating an object of nextClass
		nextClass nextclass=new nextClass();	
		// creating a constructor of firstConstructor class
		firstConstructor first=new firstConstructor(200);
		//getting the value of variable i from the constructor element


public class firstConstructor {
	public int i;
	public firstConstructor(int input) {


public class nextClass {

	public void display_now() {

output :

You can create an object of their class by referring to code above

An object is a variable that contains instance of that particular class. This is used to interface all the methods inside that class



A constructor is an instance object of a class that initializes the values for a particular class.


"this" variable

this is particularly used to refer the current object. In many cases when in a class you want to refer to current object multiple times, instead of using the object variable, you can use this to refer to current object.

Related Tutorials