The process of binding data members and methods in a single unit is known as class.
Syntax to declare a class:
class <name of the class>
{
declare data member;
declare method;
}
Example:
public class Employee
{
String name;
int age;
double sal;
public void getEmpDetails(int age,String name,double sal)
{
this.age=age;
this.name=name;
this.sal=sal;
}
public void displayEmpDetails()
{
System.out.println( name + " " + age + " " + sal );
}
public static void main(String args[])
{
Employees obj=new Employee();
obj.getEmpDetails(22,"mahesh", 20000.00);
obj.displayEmpDetails();
}
}
No comments:
Post a Comment