MainMenu

Home Java Overview Maven Tutorials

Sunday, 15 January 2017

Encapsulation in Java with example

Encapsulation in Java with example:


For Video : CLICK HERE



Encapsulation is also known as Data hiding.
If a class have private member & it is required to access these private member from outside of class then we have to create public getter & setter method.


This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes.

Encapsulation Example


class chandan
{
private string Name;
private Int Age;
public string getName()
{
return Name;
}
public void setName(String Name)
{
this.Name = Name;
}
public int getAge()
{
return Age;
}
public void setAge(int Age)
{
this.Age = Age;
}
}
public class Chandan1
{
public static void main(String args[])
{
chandan obj = new chandan();
obj.setName("Chandan");
obj.setAge(25);
System.out.println("Your name is :" +obj.getName);
System.out.println("Your Age is :" +obj.getAge);
}
}
Output :
Your name is :Chandan
Your Age is :25

Tags :What is Encapsulation?,Encapsulation Example in Java

6 comments:

  1. Replies
    1. IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

      Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
      Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
    selenium training in chennai
    selenium online courses best selenium online training
    selenium testing training
    selenium classes

    ReplyDelete
  3. I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon… click here

    ReplyDelete