Submit Your Site To The Web's Top 50 Search Engines for Free! Java Tutorial: Learn Java Basics For Free | Learn Java

Thursday, October 3, 2019

What is “tightly encapsulation” in Java? - Learn Java

What is “tightly encapsulation” in Java? - Learn Java

Encapsulation In Java With Realtime Example

A class is said to be tightly encapsulated
If and only if each and every variable of class declared as private.

And there is  no need to be worry about whether class contains corresponding 
getter and setter methods or not or whether these methods are declare as public 
or not.

Encapsulation In Java With Realtime Example:

Example:1
public class Account
  {
           private double balance;
           public double getBalance()
          {
                return balance;
          }
  }

Which of the following classes are tightly encapsulated

 public class A
 {
    private int x=11;(Valid)
 }
class B extends A
 {
    int y=20;(Invalid)
 }
 class C extends A
{
private int z=40;(Valid)
 }

Note : If the parent class is not tightly  encapsulated then  
child class will  not be tightly encapsulated.

learn java online free and learn java programming this is the
best way to learn java. this is best java tutorial.in this tutorial          
all the programs start with hello java,hello world.Enterprise applications         
programming language

2 comments:

  1. xcellent information provided by you through this post. I follow all the mentioned information.If you are looking for Interview Questions and answers website then you can visit Just Crack Interview, here you will find interview questions and answers for developer, software engineer, bankers etc.

    ReplyDelete

Java Inheritance Update 2023 With Program And Example

  Java Inheritance Update 2023 With Program And Example  nheritance is one of the essential concepts in object-orientated programming  (OOP)...