Tuesday, October 1, 2019

How to use class in java program


//class 
class student
{
String name;
int roll_no;
}
//main class
class ans
{
//main function
public static void main(String args[])
{
//object declaration
student s = new student();
s.name = "John";
s.roll_no = 18;
//print function
System.out.println("Name is" +s.name+ "and roll number is" +s.roll_no);
}
}

Output : Name is John and roll number is 18.

No comments:

Post a Comment