I am beginner on java and i am having trouble while compiling below given code on CMD.
This code is taken from a book.
E:\sher\SkyDrive\Exercise Files\L04>javac Student.java
E:\sher\SkyDrive\Exercise Files\L04>java Student
Exception in thread "main" java.lang.NoSuchMethodError: main
// Student.java
/* Demostrates the most basic features of a class. A student is defined by their
name and rollNo. There are standard get/set accessors for name and rollNo. */
// public Static Void main (String args[]){}
public class Student{
private String name;
private int rollNo;
// Standard Setters
public void setName (String name){
this.name=name;
}
// Note the masking of class level variable rollNo.
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;
}
// Constructor that uses a default value instead of taking an argument.
public Student() {
name = "not set";
rollNo = 100;
}
//parameterized Constructor for a new student
public Student(String name, int rollNo){
setName(name); //call to setter of name
setRollNo(rollNo); //call to setter of rollNo
}
//copy Constructor for a new student
public Student(Student s){
name = s.name;
rollNo = s.rollNo;
}
//method used to display method on console
public void print(){
System.out.println("Student name:" + name + ",roll no:" + rollNo);
}
}// end of class