Friday, 13 September 2013

Chapter 6 More About Classes and Libraries

CHAPTER-6
MORE ABOUT CLASSES AND LIBRARIES
Brief Summary of the Chapter:
In this chapter the way access of members of a class i.e. about access specifier will be discuss. Java include predefined classes in the form of packages which are also called Java class Library. Some of the used packages are: java.lang. java.util, java.io, java.swing. java.awt, java.applet etc.
Key points:
·   The public member of object are accessed through .(dot) operator.
·   The private members are accessible only inside their own class.
·   The protected members are accessible inside their own class, sub class and packages.
·   The default members are accessible inside their own class as well to classes in the same
     
package.
·   Related classes and interfaces are grouped together in the form of package. ·   Packages and class are imported through import command.
SOLVED QUESTIONS
1. Which keyword can protect a class in a package from accessibility by the classes outside the package?
(a)private (b)protected (c) final (d) None of these Ans: (d) None of these.
2. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
(a)private (b)protected (c) final   (d) public (e) None of these
Ans: (b) protected.
3. Which of the following keywords are used to control access to a class member?
(a) default (b) abstract (c)protected (d) interface (e) public.
Ans: (c) and (e) public
4. The public members of objects are accessed through which operator.
(a) arrow (b) dot   (c) this (d) none of these
Ans: (b) dot
5. The private members are accessible only inside their _______class.
(a) own (b) sub (c) super (d) none of these
Ans: (a) own
6. Which command is used to import packages and their classes?
(a) include (b) import (c) public (d) inline
Ans: (b) import
7.Which statement is used to create a package in Java?
(a) Class (b) super (c) this (d) package


                 Ans:(d) package
8. In Java, all strings are objects?
(a) True (b) False (c) don’t say
Ans: (a) True

9. What do you understand by Package in Java?
Ans: A group of classes is called package 
14.What are the access specifiers in Java? Expalin.
Ans: The Access Specifiers control access to members of class from / within Java Program. Java supports various Access Specifiers to control the accessibility of class members.
   
Private : A variable or method declared as private, may not be accessed outside of the class. Only
class member can access them, since they are private to others.
Protected: Protected members can be accessed by the class members and subclasses (derived
classes) and current package, but they are not accessible from beyond package or outside.
Public: Class members declared as public, are accessible to any other class i.e. everywhere , since they are public.
Package (default): If no any specifier is mentioned, default or friendly access is assumed. Class member may be accessed by any other Class members available in the same package, but not accessible by the other classes outside the package, even subclasses. 

No comments:

Post a Comment