Java Class Example – Class in Java Example Program

By | December 17, 2010
Java Class Example - Class in Java Example Program. You can find Source code for Class in Java.

Java Class Example – Class in Java Example Program. You can find Source code for Class in Java.

class Student{

int rollNumber = 101;

String name = “eshusoft”;

void setStudent(int rno,String sname){

rollNumber=rno;

name=sname;

}

void display(){

System.out.println(“rollNumber =”+rollNumber);

System.out.println(“name =”+name);

}

}

public class ClassDemo {

public static void main(String[] args) {

Student obj = new Student();

System.out.println(“student object is created”);

System.out.println(“Roll Number:” + obj.rollNumber);

System.out.println(“Name:” + obj.name);

obj.display();

obj.setStudent(201, “eshusoft123”);

System.out.println(“student object is created”);

System.out.println(“Roll Number:” + obj.rollNumber);

obj.display();

}

}

Result:

student object is created

Roll Number:101

Name:eshusoft

rollNumber =101

name =eshusoft

One thought on “Java Class Example – Class in Java Example Program

Leave a Reply

Your email address will not be published. Required fields are marked *