CoreJavaTutorials
Contribute Us | Ask Question |

Classes and Object

Classes are the template or a blue print for the object .Class is act as a container for object.
Object concept are derived from the real world object.It seems as a real world object like a car ,a apple etc.

Example- like an orange, an apple, grapes all are fruit so they can be contained into class name fruit.The structure is given below:

class fruit
{
String apple;

String orange;

String grapes;
}
		

The concept of class and object are the basic concept of object oriented programming language which change the way of programming. It make a programming more simplified and understandable because a programmer can start programming by take a example of real world.

A full example of class and object with output is given below:

class TestClass
{
String apple= " a very tasty apple ";
public static void main (String args[])
{
TestClass tc=new TestClass();
System.out.print(tc.apple);
}
}
Output
Javac TestClass.java
Java TestClass
A very tasty apple

		

Detailed Description:
TestClass is name of class
String apple; -> apple is a variable String is a datatype
TestClass tc=new TestClass();
tc is an object that access the apple value;