Java Class Example – Class in Java Example Program

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 comment

  • 1
    arfan iqbal
    May 13, 2013 - 11:59 am | Permalink

    Plese tell me constructor or classes in java.