Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

Java Programming

Java – Encapsulation in Java

Encapsulation in Java

Encapsulation is a protective mechanism by which members of a class (method and variables) are prevented from being accessed by members of other class.  

The best example of encapsulation is the class because that binds its variables and methods and hides their complexity from other class.  

In a class, the general variables and methods are defined or marked as private, protected and the public to bind the data from unauthorized access.

Java Source

public class Inclass {
private String name;
private String subject;

public void hola(String n, String sn){
System.out.println(name+"'MyName:'"+subject+"'I Love'");

public static void main(String[] args) {
Inclass s = new Inclass();
s.hola("Satya", "Math");



About Author provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

introduction to java programming
Java Programming

Java – Introduction, Features, Versions & History

  • December 20, 2020
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented. Java inherits its object-oriented features from C++. Java
basic terms of java programming
Java Programming

Java – Basic Terms of Java Programming

  • December 20, 2020
A Java program, similar to programs in other programming languages, It also uses the literals, variables, tokens, data types, etc.