0

(JAVA) Is is correct how I describe each part where will be stored?

Hello everyone, I have a code and I should define where each part is stored, 1- Method Area 2- Heap 3- Stack so I wrote it down and wanted to check with you if it is correct or needs some correction, please help me understand it. The code is the following ______________________________________________________________________ public class TestStudent { static Student studentA; static Student studentB; static Student studentC; public static void main(String[] args) { studentA = new Student("Mark", "John", "Jimmy"); studentB = new Student("Will", "George", "Androw"); studentC = new Student("Frank", "Sam"); int totalStudents = Student.getTotalStudents(); System.out.println(totalStudents + " is 3"); System.out.println(studentA.getFirstName() + " is Mark"); studentA.setFirstName("Richard"); System.out.println(studentA.getFirstName() + " is Richard"); } _____________________________________________________________________ Here is my definition of each part and where will be stored: - The whole byte code will be stored in the Method Area - The class TestStudent will be stored in the Method Area - The Global Variables studentA, studentB, and studentC will be stored in the Stack - class main will be stored in the Method Area as well - The objects studentA, studentB, and studentC will be stored in the Heap - The result of totalStudents studentA.getFirstName() and the new result of studentA.getFirstName() both will be stored in the Stack - This new object studentA will be stored in the Heap _____________________________________________________________________ Thanks in advance

10th May 2020, 2:25 PM
Mohammad Ala Tahhan
Mohammad Ala Tahhan - avatar
2 odpowiedzi
+ 2
studentA, studentB, studentC are all reference variables which are created on the stack. The actual objects with the new keyword are stored on the heap. The ones on the stack just hold the reference to the corresponding objects. Rest of it looks good.
10th May 2020, 2:38 PM
Avinesh
Avinesh - avatar
+ 2
You are correct. Keep going.
10th May 2020, 2:33 PM
Tarun Kumar
Tarun Kumar - avatar