0% found this document useful (0 votes)
85 views2 pages

Encapsulation Worksheet

The document discusses two chapters: Chapter 8 on encapsulation and Chapter 2 on library classes in Java. Chapter 8 defines encapsulation as wrapping data and methods into a single unit using access specifiers like private, protected, and public. It also discusses inheritance and how encapsulation achieves data hiding. Chapter 2 discusses wrapper classes in Java like Integer and Character that allow primitive values to be used as objects. It covers parsing strings to numbers, character initialization, and methods on wrapper classes.

Uploaded by

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

Encapsulation Worksheet

The document discusses two chapters: Chapter 8 on encapsulation and Chapter 2 on library classes in Java. Chapter 8 defines encapsulation as wrapping data and methods into a single unit using access specifiers like private, protected, and public. It also discusses inheritance and how encapsulation achieves data hiding. Chapter 2 discusses wrapper classes in Java like Integer and Character that allow primitive values to be used as objects. It covers parsing strings to numbers, character initialization, and methods on wrapper classes.

Uploaded by

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

Chapter 8: Encapsulation

1. Which access specifier allows accessibility of a member only within the same class where it is
declared?
a. public b. private
c. protected d. default

2. Wrapping up of data and method into a single unit is called _________.


a. Encapsulation b. Abstraction
c. Inheritance d. Polymorphism

3. An OOP feature that allows all members of a class to be the members of another class.
a. Encapsulation b. Abstraction
c. Inheritance d. Polymorphism

4. Which keyword allows Inheritance?


a. extend b. extends
c. for d. protected

5. Which access specifier allows accessibility by all classes in the same package, but only by
subclasses in a different package?
a. public b. private
c. protected d. default

6. A static member a is declared in a class named ‘Myclass’, write the statement to initialise it with
5, from a function in another class.
a. a=5; b. a of Myclass=5;
c. Myclass.a=5; d. a.Myclass=5;

7. Which among the following best describes encapsulation?


a. It is a way of combining various data members into a single unit
b. It is a way of combining various member functions into a single unit
c. It is a way of combining various data members and member functions into a single unit which can operate on any data
d. It is a way of combining various data members and member functions that operate on those data members into a
single unit

8. If data members are private, what can we do to access them from the class object?
a. Create public member functions to access those data members
b. Create private member functions to access those data members
c. Create protected member functions to access those data members
d. Private data members can never be accessed from outside the class

9. Which feature can be implemented using encapsulation?


a. Inheritance b. Abstraction
c. Polymorphism d. Overloading

10. How can Encapsulation be achieved?


a. Using Access Specifiers b. Using only private members
c. Using inheritance d. Using Abstraction
Chapter 2: Library classes
1. Which of the following is a composite data type?
a. int b. String
c. char d. float

2. Which of the following is not a wrapper class?


a. Byte b. Int
c. Long d. Float
3. Which of the following is valid method of initialising?
a. Integer a=new (5); b. Integer a=Integer(5);
c. Integer a=new Integer(5); d. Integer a=new (“5”);

4. If s=“123”, which among the following will convert it to an integer?


a. int a=Integer(s); b. int a=(int)s;
c. int a=parseInt(s); d. int a=Integer.parseInt(a);

5. Which among the following is valid character initialisation?


a. Character c=new Character(‘c’); b. Character c=new Character(“c”);
c. Both a and b d. None of these

6. Which among the following methods return a true or a false?


a. toLowerCase() b. toUpperCase()
c. parseInt() d. isUpperCase()

7. What package is a part of the wrapper class which is imported by default into all Java programs?
a. java.util b. java.lang
c. java.awt d. None of these

8. Which class is inherited by the Character and Boolean wrapper classes?


a. Object b. Number
c. Both a and b d. None of these

9. What is, converting a primitive value into an object of the corresponding wrapper class called?
a. Autoboxing b. Unboxing
c. Type Casting d. All of these

10. Which among the following function is used to check whether a given character is a tab space or not?
a. isTab() b. isTabSpace()
c. isSpace() d. isWhitespace()

You might also like