Java Reference
In-Depth Information
MVC implementation
Now that we have defined our classes for MVC, let us write some code. Code for the model
public class Model {
private String rollNo;
private String name;
public String getRollNo() {
return rollNo;
public void setRollNo(String rollNo) {
this.rollNo = rollNo;
public String getName() {
return name;
public void setName(String name) { = name;
In the model , we are defining student roll number and student name using private class vari-
ables and get and set methods. Since the class variables are declared private so they are not
accessible from outside and so are totally safe.
Now we will write the class for view.
public class View {
public void printStudentDetails(String studentName, String studentRollNo){
System.out.println("Student: ");
System.out.println("Name: " + studentName);
System.out.println("Roll No: " + studentRollNo);
Search WWH ::

Custom Search