In my java code

```
package com.luv2code.jsp.tagdemo;
public class Student {
    public String firstName;
    public String lastName;
    public boolean goldCustomer;
    public Student(String firstName, String lastName, boolean goldCustomer) {
        super();
        this.firstName = firstName;
        this.lastName = lastName;
        this.goldCustomer = goldCustomer;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public boolean isGoldCustomer() {
        return goldCustomer;
    }
    public void setGoldCustomer(boolean goldCustomer) {
        this.goldCustomer = goldCustomer;
    }

}

```

In JSP Code

```
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.*,com.luv2code.jsp.tagdemo.Student" %>
<%
    ArrayList<Student> data=new ArrayList<>();
    data.add(new Student("Subhajit","Maity",true));
    data.add(new Student("Biswajit","Kundu",true));
    data.add(new Student("Sourav","Das",false));
    pageContext.setAttribute("myStudent", data);
%>

<html>
<head>
</head>
<body>
<c:forEach var="tempStudent" items="${myStudent}">
    ${tempStudent.firstName}
</c:forEach>

</body>
</html>

```

If I use getter and setter method for setting and getting the firstname,lastname and goldcustomer then the code works fine.But with out getter and setter it gives error.If I declare the class variable as public then it can be accessible to any where then ahy should I use getter and setter menthod?