Java Encapsulation Basics

Day 58/200 - Java Learning Journey 🌱 ✨ Sharing what I learned today in Java. 📚 Today I learned about Encapsulation in Java Today's Topic: Encapsulation ✴️ Encapsulation: 👉 It means wrapping(hiding) the data (variables,methods) and providing the controlled access. 🔯 Advantages/Features: 🔺 Security 🔺 Hiding the data 🔺 Controlled access 🔺 Validation 🔺 Flexibility 🔆 How to hide the data ❓ ▪️ By making those variables,methods to be private. 1️⃣ Setters: 👉 These are used to set the data. 2️⃣ Getters: 👉 Get or return the data. 🔸 Syntax: For setters: access_modifier returntype(void) settersName(){ -------------//data } For getters: access_modifier returntype gettersName(){ return value; } 💠 Without setters we cant use getters. 💠 Without getters we can set the value by using setters. 👎 Drawback: 👉 In Encapsulation for each and every variables we need to use setters to set the value to those variables. #Java#Encapsulation#OOPS#DailyLearning#Consistency#Meghana M#10000 Coders#

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories