.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Ava Aiden
Imran Ghani
Thomas Shaw

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

difference between the code in encapsulation concept.

Posted By: Naresh     Posted Date: January 19, 2011    Points:2   Category :ASP.Net
Hi All,

can u tell What makes the difference with below code with encapsualtion and without encapsulation.

class person{
private String name;
private int pn;
name = "bob";
pn = 10;
person(String name){
this.name = name;
pn = 10;
person(String name, int pn){
this.name = name;
this.pn = pn;
public String lookupname(){
return name;
public int lookupnum(){
return pn;

public class loblah{
public static void main(String[] args){
person chris = new person("Chris", 100);
person john = new person("John");
person liz = new person();

code without encapsualtion

class Person{
public String name;
public int pn;

public class Loblah{
public static void main(String[] args){
Person chris = new Person();
chris.name = "Chris";
chris.pn = 10;
Person john = new Person();
john.name = "John";
john.pn = 20;
Person liz = new Person();
liz.name = "Liz";
liz.pn = 30;
System.out.println(liz.name + " " + liz.pn);
System.out.println(john.name + " " + john.pn);
System.out.println(chris.name + " " + chris.pn);

Author: Jean Paul             
Posted Date: January 25, 2011     Points: 5   

What is this?

Jean Paul http://jeanpaulva.com/

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend