Page 471 - Cs_withBlue_J_C11_Flipbook
P. 471
Unsolved Questions
A. Tick ( ) the correct option:
1. BufferedReader class belongs to package ………………… .
a. util b. IO
c. lang d. io
2. Which of the following is not an advantage of using a package?
a. Polymorphism b. Eliminates naming collision
c. Provides access protection d. Reusability
3. To access class CompProj in package mypackage, we write ………………… .
a. import CompProj.mypackage; b. import mypackage.CompProj;
c. package CompProj.mypackage; d. package mypackage.CompProj;
4. Which of the following is defined as a blueprint or prototype of similar objects?
a. String b. class
c. package d. mysql
5. Which of the following options contains classes and packages that are helpful in minimising and simplifying Java coding, like java.
lang, java.util, java.io, etc.?
a. JDK b. API
c. Packages d. StringTokenizer
B. Fill in the blanks:
1. Full form of API is ………………… .
2. ………………… access must be given to access a class from a different package.
3. To use StringTokenizer class we have to import ………………… .
4. To create a new package in BlueJ choose ………………… option on BlueJ menu and from the drop-down list click ………………… .
5. The packages already defined in Java software are known as ………………… packages.
C. Answer the following questions:
1. What is a package? Write two advantages of using package.
2. Name any two built-in packages and write their functions.
3. Write how public access works in:
a. same class b. same package
c. subclass outside package d. outside package
4. What are user-defined packages?
5. How can we access any package?
#Coding & Computational Thinking
D. Unsolved Programs: #Interdisciplinary
1. Write a program to create a package Comprac containing class CountDig having the following specifications.
Package : Comprac
Class name : CountDig
Data Members
int n : Stores number as binary
Member Methods
CountDig(int x) : Constructor to assign the data members
int count() : Counts and returns number of 1’s in a binary number
Write a second class Odious in package Green to import class CountDig of package Comprac and use the method count() to print
if a number is an odious number or not. An Odious number is a non-negative number that has an odd number of 1s in its binary
expansion.
469
Packages 469

