Dear Sir ,
I am a beginner at java .It is my third program written for Student class .
I got it compiled normally , but am receiving a runtime exception .
It reads as :
Exception in the thread main
java. lang. NoSuchMethodError : main
I checked the code word by word , line by line , but I could not locate the error . Plz go through it and let me know where the error lies. ? Plz send me the code , if you need to modified it. Or let me know the steps , how should I proceed.
Code on Notepad as Java file :
/* 786 */
/* File Name Student.java */
public class Student {
private String name ;
private int rollNo ;
/* ***** Setters ****** */
public void setName ( String name){
this.name = name ;
}
/* ***** class lvel variable ***** */
public void setRollNo ( int rollNo ) {
if ( rollNo > 0 ) {
this.rollNo = rollNo ;
}
else {
this.rollNo = 100 ;
}
}
/* ***** standard getters ***** */
public String getName () {
return name ;
}
public int getRollNo () {
return rollNo ;
}
/* ***** Default constructor ***** */
public Student () {
name = " not set " ;
rollNo = 100 ;
}
/* ***** parameterized constructor for a new
student ***** */
public Student ( String name , int rollNo) {
setName (name) ;
setRollNo (rollNo) ;
}
/* ***** copy constructor for a new student ***** */
public Student ( Student s ) {
name = s.name ;
rollNo = s.rollNo ;
}
/* ***** method used to diplay on consol ***** */
public void print () {
System.out.print ( " Student name : " +name) ;
System.out.print ( " , roll no : " +rollNo) ;
}
} // ****** end of class
code ends here .
I have done as below :
Copied the code on notepad and saved as java file
Gave command < javac Student.java >
It worked / compiled successfully .
Gave command < java Student >
Got the Exception error.
Your help is solicited.
Thanks.