Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

Class Declaration Demo

/**
* Write an application which declares a class named Person. It should have
* instance members to record name,age and salary. Print all of them.
*
*
*/
class Person {
// stores person name
private String strName;

// stores person salary and age
private int intSal, intAge;

/**
* constructor with arguments
*/
Person(String name, int sal, int age) {
strName = name;
intSal = sal;
intAge = age;
}

/**
* display the member variables values
*
*/
public void display() {
System.out.println("\tName : " + strName + "\n\tAge : " + intAge
+ "\n\tSalary : " + intSal);
}
}

/**
* it will create object of Person class and displays its content
*
* @author Ritesh
*
*/
public class Employee {

/**
* excution begin from here
*
* @param args
* command line arguments
*/
public static void main(String[] args) {
Person person = new Person("Ritesh", 9000000, 25);
System.out.println("Person : ");
person.display();
}
}

No comments:

Post a Comment

Followers