
wap to show concept of class in java

Hi Friend,
A class is the blueprint from which individual objects are created. Whatever we can see in this world, all the things are object. And all the objects are categorized in a special group. That group is termed as a class.
Here is a sample code:
class Person {
String name = "";
int age = 0;
void changeName(String name1) {
name = name1;
}
void changeAge(int age1) {
age = age1;
}
void print() {
System.out.println("Name:"+name+"\nAge:"+age);
}
}
class PersonInformation{
public static void main(String[]args){
Person p=new Person();
p.changeName("B");
p.changeAge(20);
p.print();
}
}
The design of this class is based on the person objects. The fields name and age represent the state of object, and the methods- changeName and changeAge define its interaction with the outside world.The Person class does not contain a main method as it is just the blueprint for persons that might be used in a program.The class PersonInformation takes the responsibility of creating and using person objects.
For more information, visit the following link:
http://www.roseindia.net/java/master-java/classes-in-java.shtml
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.