0% found this document useful (0 votes)
341 views7 pages

Class 10 Notes On Encapsulation

The document discusses encapsulation and class concepts in Java. It defines encapsulation as wrapping data and methods into a class, and explains how classes can enforce information hiding through access specifiers like public, private, and protected. The document also differentiates between static and instance variables and methods, and local and global variables.

Uploaded by

ishitahhs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
341 views7 pages

Class 10 Notes On Encapsulation

The document discusses encapsulation and class concepts in Java. It defines encapsulation as wrapping data and methods into a class, and explains how classes can enforce information hiding through access specifiers like public, private, and protected. The document also differentiates between static and instance variables and methods, and local and global variables.

Uploaded by

ishitahhs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

FAQ’S on Encapsulation

Explain the term ‘Encapsulation’ with an example? [2006]

Ans: The wrapping up to data and methods into a single unit(called class) is known as Encapsulation. For

example an engine of car or any vehicle contains many small parts, which enables the entire machinery system

to work. Encapsulation property hides the inner working of objects from the real world.

What does a class encapsulate?

Ans: A class encapsulates Data Members that contains the information necessary to represent the class and

Member Functions that perform operations on the data member.

How does a class enforce information hiding?

Ans: Classes enforce information hiding by means of access specifier.

Define the term visibility?

Ans: Visibility is a related term which refers to whether one can use a variable from a given place in the

program.

What is visibility modifiers?

Ans: It is also called access specifier. It defines which function or method is able to use this method.

Explain the different types of access specifier?

Ans: Access specifier can be of following types:

(a) PUBLIC: It means that any one can call this method.

(b) PRIVATE: It means that only the methods in the same class are permitted to use this method.

(c) PROTECTED: It means that methods in this class and methods in any subclass may access this method.

pg. 1
pg. 2
Define variable’s scope (scope rule)?

Ans: The program parts in which a particular data value (e.g., variable) can be accessed is known as variable’s

scope.

Differentiate between public and private modifiers for members of a class.

Public Modifier Private Modifier

It must open access level. It is lowest access level.

It can be accessed by any class, package. It can be accessed only by the member within class.

Differentiate between private and protected visibility modifiers.


Private Modifier Protected Modifier

It can be accessed by the same class to which the


methods and fields belong. It can be accessed by the subclass.

Private method and fields are not visible within Protected method and fields are visible
subclass. within subclass.

What is meant by private visibility of a method?


Private visibility of a method means that methods is accessible only in same class and can not be accessed by
child class or in other class.

Explain about friendly modifier.


Friendly modifier is not a keyword. If you don’t specify any access modifier, by default it is friendly.

Different Types of Variables

pg. 3
What is the default value of local variable?
The local variables are not initialised to any default value, neither primitives not object references.

Define static members?

Ans: The members that are declared static are called static members. These members are associate with the

class it self rather than individual objects.

What are static variables?

Ans: Static variables are used when we want to have a variable common to all instances of a class.

What are the restrictions of static methods?

Ans: (i) They can only call other static methods.

(ii) They can only access static data.

(iii) They cannot refer to ‘this’ or ‘super’ keywords in anyway.

Explain instance variable. Give an Example. [2008]

Ans: A data member that is created for every objects of the class.

public class abc

pg. 4
{

int a,b; // instance variable or data member

What is initial class?

Ans: A java program contains many classes. But one class in a Java program contains the main() method. This

class is called initial class.

What is Class variable (Static Variable)?

Ans: A data member that is declared once for a class. All objects of that class type, share these data members, as

there is single copy of them available in memory. Keyword ‘Static’ in the variable declaration makes a class

variable.

What is Instance variable? [2007] [2008]

Ans: A data member that is created for every objects of the class.

What does the class consists of ?

Ans: A class consists of:

(i) Data members: It contain information necessary to represent that class .

(ii) Methods: It perform operations on the data members of the class.

What is the purpose of static methods and static variables?


Static variables are used when there is a requirement to share a variable between multiple objects of a class
instead of creating separate copies for each object.

pg. 5
Static method are used to be loaded in the memory without creating any object of that class in which method is
defined.

Define the term Local variable and Global variable.

Ans: Local Variable: Variable declared inside a method or block.

Global Variable: Class variable which is available to the entire class.

Mention the levels of scope and visibility offered by java?

Ans: (i) Data declared at the class level can be used by all methods in the class.

(ii) Data declared within a method can be used only in the method.

(iii) Data declared within a method is called local data.

(iv) Variable that are declared in block i.e., local variable are available to every method inside of the block.

(v) Variable declared in interior blocks are not available outside of that block.

(vi) Variable declared in exterior blocks are visible to the interior blocks.

What are member variables? State their types?

Ans: Member variables are also known as Instance variables. These member variables are used to store value in

the class. It may be public, private and protected, where private and protected members remains hidden from

outside world and there by support data.

What is meant by private visibility of a method? [2006]

Ans: PRIVATE visibility of a Method means that only the methods in the same class are permitted to use this

method.

Can a private member of a public class can be accessed by


i) same class?

ii) other class in the same package?

iii) class of some other package?

Answer : i) Yes, private member of a public class can be accessed by same class.
ii) No, other classes are unable to access private member of a public class.

iii) No, other package’s class can not access private member of a public class.
pg. 6
pg. 7

You might also like