Skip to content
Advertisement

Accessible and Modifiable data?

what is the difference between accessible and modifiable data in the variable grade in terms of accessibility from outside the class?

This is my code where i’m calling grade method from outside the class:

package studenttester;

public class student {

    private String name;
    private int age;
    private String grade;
    private double average;
    private boolean disability;
    
    
    private void printStudentInfo(){ //Data Encapsulation is methods of the public interface provide access to private data, while hiding implementation. 

        System.out.println("Name: "+name+",Age: "+age+",Grade: "+grade+",Average: "+average +" Disability: "+disability);
    } 
    
    public void setGrade(String newGrade){
        grade=newGrade;
    }
    
    public String getGrade(){
        return grade;
    }
 }
    public class StudentTester{
public static void main(String[] args){
       student S1 = new student(); 
       student S2 = new student(); 

       S1.setGrade("11");
       System.out.println("Student one: " +S1.getGrade()+", Student two: "+S2.getGrade());

       /* The instance variables are name, age, grade, average, disability and those are the variables that the object S2 contains. The object’s attributes are : name, age, grade, average, disability. 

       S1 attributes values : name: null , age:0, grade:"11", average : 0.0, disability: false
       S2 attributes values : name: null , age:0, grade:null, average : 0.0, disability: false */

}
}

Advertisement

Answer

accessible data means you can only access .we can you only view or access the data it can not be modified or changed

whereas modifiable can be modified or can be changed.

you can say accessible data are constant and modifiable data are variables

Advertisement