Skip to content

Conversation

hp113
Copy link

@hp113 hp113 commented May 16, 2025

This pull request resolves a compilation error in the Java Aggregation example.

🔧 Changes Made:
Added a getName() method in the Professor class to properly access the private name field.

Replaced direct field access (professor.name) in the University class with a call to professor.getName().

🐞 Issue Fixed:
In the original code, the showProfessors() method attempted to access professor.name, which is declared private in the Professor class. This violates encapsulation and causes a compilation error.

✅ Outcome:
The updated code now compiles and runs correctly, maintaining object-oriented principles by using proper encapsulation.

Before Changes:
image

After Changes:
image

@hp113 hp113 changed the title Fix private field access error in Aggregation example by adding getter methodUpdated Java code in aggregation README Fix private field access error in Aggregation example by adding getter method May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant