Java class

CLASS

  • Class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors.
  • Java class objects exhibit the properties and behaviors defined by its class. A class can contain fields and methods to describe the behavior of an object.

Declaration of Class in Java
class keyword followed by class name
class student student is class name
The entire body is written within curly bracket { }

Demonstration of Class
class Student
{
public static void main(String[] args)
{
String name=”Devilx”;
int rollno=526;
int id=1;
System.out.println(“student name is: “+name);
System.out.println(“student roll number is: “+rollno);
System.out.println(“student id is: “+id);
}
}

output : student name is: Devil
student roll number is: 526
student id is: 1

In above program the student is class name and followed by class keyword, and String name is variable having string data type . the first letter should be capital while declaring string in java, which is  storing string value Devilx , 526 is int value (integer) stored in variable rollno. ..

java Programme to add two decimal number
class AddNumber
{
public static void main(String[] args)
{
double x=40.44;
double y=50.44;
double z=x+y;
System.out.println(“The sum of x and y is: “+z);
}
}

output : The sum of x and y is : 90.88
AddNumber is class
double is data type
x, y, z are variables or data member of class AddNumber

BACK

NEXT