Accenture Java Programming Practice Question
Consider the below code snippet and determine the output. class Student { private int studentId; private float average; } class Test { public static void main(String a[]) { Student s=new Student(); s.studentId=123; System.out.println(s.studentId); } }Answer options
A
Compile-time error
B
Prints 123
C
0
D
Runs with no output
Correct answer: Compile-time error
Explanation
studentId is private; accessing it from Test directly causes a compile-time error.