how do you implement an instance variable in java

Solutions on MaxInterview for how do you implement an instance variable in java by the best coders in the world

showing results for - "how do you implement an instance variable in java"
Liana
06 May 2020
1package Edureka;
2 
3import java.util.Scanner;
4 
5public class Student
6{
7 
8public String name;
9 
10private int marks;
11 
12public Student (String stuName) {
13name = stuName;
14}
15public void setMarks(int stuMar) {
16marks = stuMar;
17}
18 
19// This method prints the student details.
20public void printStu() {
21System.out.println("Name: " + name );
22System.out.println("Marks:" + marks);
23}
24 
25public static void main(String args[]) {
26Student StuOne = new Student("Ross");
27Student StuTwo = new Student("Rachel");
28Student StuThree = new Student("Phoebe");
29 
30StuOne.setMarks(98);
31StuTwo.setMarks(89);
32StuThree.setMarks(90);
33 
34StuOne.printStu();
35StuTwo.printStu();
36StuThree.printStu();
37 
38}
39}
40