What is the difference between public, private, and protected in Java?
Автор: VAISHNAVI MAURYA
Загружено: 2024-09-01
Просмотров: 10
Public --
Visibility : Anything marked as public can be accessed from anywhere in your program. This means that other classes, even those in different packages, can see and use it.
Use Case : You use public when you want your code to be accessible to everyone. For example, a method that anyone should be able to call.
private --
Visibility : Anything marked as private can only be accessed within the same class. Other classes, even in the same package, cannot see or use it.
Use Case : You use private when you want to hide the details of your code and only allow access through specific methods (like getters or setters).
protected --
Visibility : Anything marked as protected can be accessed by :
1. The same class,
2. Classes in the same package,
3. And subclasses (even if they are in different packages).
Use Case : You use protected when you want to allow access to subclasses but still keep some control over who can see or use your code.
Top Core Java Interview Questions || Core Java Interview Questions and Answers [MOST ASKED]
Java Interview Questions and Answers | Java Tutorial | Java Online Training
Checkout Java Full Course -
Anuj Bhaiya
• Complete Java in one Video | Java Tutorial...
Apna college
• Java Tutorial for Beginners | Learn Java i...
Kg coding by Prasant sir
• 🚀🔥 JAVA Complete Course Part-1 (2024) | 10...
#computerscience #easyquestions #interview #interviewquestions #placement #shortvideo #tcs #wipro #java #javainterviewquestionsandanswersforfreshers #shorts #shorts #freshers #javainterviewquestionsandanswers

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: