ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
What is meant by Encapsulation? Can you write a class to
explain encapsulation?
 Question Submitted By :: Maria
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 1
Encapsulation is process binding data with an object.  
Object consists data and methods, where methods helps to 
extract or set data. 

  All classes developed using OOPS concepts follow the 
encapsulation.
 
Is This Answer Correct ?    6 Yes 1 No
Bln
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 2
It is the ability of an object to hide its data and methods 
from the rest of the world.

A Class may contains a few members in the form of 
properties,events,fields or methods.These members of the 
class are not exposed to the outer world directly.Rather 
they are ENCAPSULATED by the Class.

Public Class Calculations
{
     Private void fnMultiply(int x, int y)
     {
        return x*y;
     }
}

Calculations Obj;
int Result;
Result = Obj.fnMultiply(5,10);
 
Is This Answer Correct ?    5 Yes 2 No
Rajasekhar
 
 
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 3
-Encapsulation is wrapping of data(Data members) and
associated methods(member functions) into a single unit in 
such a way that data can be accessed with the help of
associated methods.
--In a class we can specify the variables(Data members) as
private. So for other classes it will not be accessible. 
--Through methods(member functions) only we can access the
member variables or modify them. 
--It gives more security for our data. It is nothing but
data hiding.
 
Is This Answer Correct ?    5 Yes 0 No
Sivakishorereddy(badvel)
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 4
Wraping of objects under a class is known as Encapsulation.

class
{
public static void main(String a[])
{
int a,b,
....
....
}
}
 
Is This Answer Correct ?    0 Yes 0 No
Ajay Kumar Sharma
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 5
Binding the Function with its associated data together is
called encapsulation(Tough definition but here is example also)

Think this senario
public class Anjani{
public int size;
public int weight;
...
}
public class Jha {
public static void main (String [] args) {
Anjani a = new Anjani();
a.size = -5; // Legal but bad!!
}
}

if somebody change ur size from -5 to -10; so sad ..........
And now you're in trouble. How are you going to change the
class in a way that
lets you handle the issues that come up when somebody
changes the size variable
to a value that causes problems? Your only choice is to go
back in and write method
code for adjusting size (a setSize(int a) method, for
example), and then
protect the size variable with, say, a private access
modifier. But as soon as you
make that change to your code, you break everyone else's!

The ability to make changes in your implementation code
without breaking the
code of others who use your code is a key benefit of
encapsulation.

Now how u will do this............

Keep instance variables protected (with an access modifier,
often private).
and Make public accessor methods, and force calling code to
use those methods
rather than directly accessing the instance variable.
and For the methods, use the JavaBeans naming convention of
set<someProperty> and get<someProperty>.


so how u will write the code........

full code of incapsulation

class Anjani{
private int size;
public int setSize(int size)
{
    this.size=size;

return size;

}
public int getSize()
{
    this.size=size;
return size;
}

}
public class jha {
public static void main (String [] args) {
Anjani a = new Anjani();
int x=a.getSize();
a.setSize(10);
System.out.println(a.setSize(10));
}
}

Thanks and Regards
Anjani Kumar Jha
09623154095
CDAC PUNE
 
Is This Answer Correct ?    1 Yes 0 No
Anjani Kumar Jha
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 6
All the javabeans written in java follows encapsulation.
In java bean variables are declared as private for 
security. will be accessed using setter and getter method.
 
Is This Answer Correct ?    0 Yes 1 No
Srinivasa
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 7
Encapsulation=DataHidding+Abstraction is called
Encapsulation is called Encapsulation

EX:-
public class A
{
  private String name;
  private  int age;
publiic setName(String name)
{
  this.name=name;
}
public String getName()
{
  return name;
}
public setAge(int age)
{
  this.age=age;
}
public int age()
{
  return age;
}
}
 
Is This Answer Correct ?    0 Yes 0 No
Srinu
 
  Re: What is meant by Encapsulation? Can you write a class to explain encapsulation?
Answer
# 8
hai thanks for giving excellent answers...
 
Is This Answer Correct ?    0 Yes 0 No
Vinoth
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is inner class? HCL5
What modifiers are used with a top level class?  2
What is the differnence between String Buffer and String builder despite having knowledge that String builder is faster than String Buffer and last one is threadsafe.please tell another important difference.  3
Which method is used to find that the object is exited or not?  1
What method is used to compare two strings ?  4
In what ways you can handle exception ?  3
what is difference between validation.xml & validation rules.xml? BirlaSoft5
what is the use of abstract class? AMDOC2
Name the types of 'priority'?  2
what is difference between type 4 driver and type 1 driver? CMC2
What is the catch or declare rule for method declarations?  1
Accenture NJ mostly ask question on Collection like 1)How to sort Objcts and how treeset sort them 2)Explain mechanism of Hashcode finding in Java 3)Name some of the Sorted collection. Accenture1
How u dubugg ur project? iFlex1
What is singleton class?  6
What is the purpose of having the concept of overloading? Ness-Technologies5
which methods consisting of the serilizable interface?  3
Which is the best way to use for String concatenation in Java? HCL5
How do you load an HTML page from an Applet ?  2
Name the package that most of the AWT events that supports event-delegation model are defined?  2
Difference between Choice and a List?  1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com