Answers for "How do you implement an instance variable in JAVA"

0

How do you implement an instance variable in JAVA

package Edureka;
 
import java.util.Scanner;
 
public class Student
{
 
public String name;
 
private int marks;
 
public Student (String stuName) {
name = stuName;
}
public void setMarks(int stuMar) {
marks = stuMar;
}
 
// This method prints the student details.
public void printStu() {
System.out.println("Name: " + name );
System.out.println("Marks:" + marks);
}
 
public static void main(String args[]) {
Student StuOne = new Student("Ross");
Student StuTwo = new Student("Rachel");
Student StuThree = new Student("Phoebe");
 
StuOne.setMarks(98);
StuTwo.setMarks(89);
StuThree.setMarks(90);
 
StuOne.printStu();
StuTwo.printStu();
StuThree.printStu();
 
}
}
Posted by: Guest on August-17-2021

Code answers related to "How do you implement an instance variable in JAVA"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language