You are on page 1of 25

POPULARPUBLICATIONS OBIECT ORIENTED PROGRAMMING

wrapper class?
WBUT 2007, 2009 c)A java package is identified : as
a folder or a file system that
6. What is a and files, related programming language. Each class in can contain
to Java many clasSes
type. The reference during programming we need to havepackage serves sp
a
Answer:
has a corresponding reterence type purpose
It may happen that a

Each primitive type in Java


These reference types belong to a rain he several classes used. T hus, it is a good proper categoriza
o ft h e s e v e r a l . a

of the primitive type.


turn holds the value
Each wrapper class Is also an immutable class ini
in Java. classes
under package.
a programming practice to nize those
classes known as Wrapper classes.
The of such classes is:
type hierarchy iscuss the different levels of access protection available
Object in Java.
WBUT 2009, 2010]
Answer:

Boolean|| Character| V o i d Refer to Question No. 1 of Short Answer Type Questions.


9,a) What is class? How does it accomplish data hiding?
Number WBUT 2009, 2010, 2013, 2017
b) When do we declare a method or class as "fina"? WBUT 2009, 2010]
Intege Ploat Answer:

a) In a class is a construct that is used as a


object-oriented programming, to blueprint,
Long Double create instances of the class (class instances, class objects, instance objects. or just

Short objects). A class defines constituent members which enable class instances to have state
Byte and behavior. Data field members (member variables or instance variables) enable a class

numeric strings into numeric values. object to maintain state. Other kinds of members, especially methods, enable a class
Wrapper classes convert
object's behavior. Class instances are of the type of the associated class.
T h e way to store primitive data in an object. public class ExampleClass
The valueOf{) method is available in all wrapper classes except Character
All wrapper classes have typeValue() method. This method returns the value of the private i n t num;
object as its primitive type. public ExampleClass
7. a) What is constructor? What does the finalize method do?
WBUT 2008, 2013, 20171 public ExampleClass (int initialNumValue)
b) Why do we overload a constructor? Explain. WBUT 2008]
c) What are the benefits of organizing classes into package? WBUT 2008] num= initialNumValue;
Answer:
a) 1" Part: Refer to Question No. 1(a) (" Part) of Long Answer Type Questions. public int getNum ( )

return num;
2nd Part:
A finalize method is a protected method of java.lang.Object. This method is called by tne void setNum (int newNumValue)
Dlic
Java garbage collector on object which is least recently used and there are no references
made tothe object for a long time. A finalize method can also be called explicitly from an num = newNumValue;

application program, but this does not ensure that the object will be garbage collected
immediately. This says that Garbage collection cannot be forced in Java. of a class
declaration. lts the blueprint for all
The above code is an example
note of the use of
the keywords private" and "public"
b) A constructor, which does not take any parameters, is known as default x
mpleclass objects. Take The actual number is hjdden
the ut IS an example of data hiding,
also called encapsulation.
constructor. Every Java class automatically provides a default constructor, to S Ihe other classes
have to use the provided
an object of the class. Constructors are also used in a situation when we try
i"ilize that other class can modify
no
values. its
While in simple cases, this really is not
lThis
e also the value of num.
values during object creation. This is done
by parameterizing constructors. is uliC methods to modify because in many cases, you do not want to provide full
known as constructor overloading. essary, it is a good practice,
OOPM-53
0OPM-52
POPULAR PUBLICATIONS OBIECT ORIENTED PROGRAMMING
visibility, or you want to do
something special
when the value of something is changed,
something aw WindowAdapter )

program.
helps wher debugging
a
This also Void windowc Loslng
class from being inherited and therefore preva.
a
public
(WindoWEvent we)
b) The 'final"' keyword prevents ny system. e x i t ( 0 ) ;
to the class's data. If a method is define
sub classing and/or changes being made
we can't provide the reimplementation
for that final method in it's derived n a
then
i.e. overriding is not possible for that method.
classes
An abstract class contains one or moBe abstract method. If all the methods are of.
abstract then use we can declare that class as abstract or interface. But in interface p e frame. setsize (400, 400);
frame.setvisble(true)
methods must be of type abstract.
We can declare final method in abstract class suppose of it is abstract too, then there isno
used to declare like that.
Final abstract int test(String str); 11. Write a program to access static variable and static
keyword properly. meth od to explain 'static
[wSUT 2015]
10. Write a Java program that uses the draw Polygon() method of Graphics clas Answer:
to draw a tiangle with endpoints (25, 30): (75, 80) and (50, 50). [WBUT 2012, 20161 Since the static variables and static methods contain the
Answer: properties of a class and not of
the individual objects, they are also known as class variables and class
import java.lang.*; methods,
respectively.
import java.util.*; The static variables and static methods of a class are also called class variables and class
mport Java.util.List: methods, respectively.
import java. io.*;
import java.awt. * ; The syntax to declare static variable is:
static return_type
mport Java.awt.event.*;
import java.awt.geom. * ;
variable name;
The syntax to access static variable is:
public class Drawtriangle extends Frame ( classname.variable_name
public Polygon mypolygon new The syntax to declare static method is:
public void paint (Graphics g) Polygon();
=

static return_type
Graphics2D ga = (Graphics2D) g; method name
The syntax to to access static method is:
(parameter list);
ga.setPaint (Color.red); class_name method name
ga.draWPolygon (mypolygon); Ifa class member is
declared as static, only one copy of that data member is created,
regardless of the number of objects. All the objects of a class share this single
copy of the
public static void static data member.
List<
maiin (String args []) {
Integer> srcpoints
new ArrayList< Integer
srcpoints:add (25) ; srcpoints.add(30);
=

>(); Program to demonstrate the


Class StaticMember s
use of static members of a class

srcpoints.add(75) ; srCpoints.add(80);
Srcpoints.add(50) ; srcpoints.add(50) ;
StatiC int i-10; //static varlable

SrCpoints.add (srcpoints.get (0)); s t a t i c void add(int x, int y) //static method

Srcpoints.add(srcpoints.get
DrawTriangle frame new (1)); = System.o u t . p r i n t l n ( "Sum of two numbers is: (x*y) ):
for (int i =
0; i DrawTriangle();
srcpoints.sie(); i++)
intx = SrCpoints.get(it+)
int y
CLass StaticExample
srcpoints.get (i);
=

frame.mypolygon.addPoint (x,, Y) Public static void main (String args [0)

frame.addwindowListener ( StaticMembers.add(30,40);//calling s t a t i c method


lnt iStaticMembers.1; /iaccessing static variable
0OPM-54 0OPM-55
POPULAR PUBLICATIONS
of i is: "+i); OBIECT ORIENTED PROGRAMMING
("Value
System.out.println

INHERITANCEAND POLYMORPHISM
The output of the program is
Sum of teo
Value of i
numbers
is: 10
is: 70 Multiple Choice Type Questions
Here, variable i and method add() are
declared as static. Therefore. oulside
class 1.
The method
int func
(int i, int j)( ) can be
the nanme of the class in
which they are delined. a) int func (int 1, int j, int k) {}) overloaded using WBUT 2007]
they are accessed using i, floati
b) int func(float
12. Write short notes on the following: Cfloat
d
func (int i, int j) {}
int func (int a, int b) {
a) Access Specifier WBUT 2005, 20061
b) Wrapper class WBUT 2008, 2012, 2015, 20161 float func (int i, int j, float k ) {}
a) (b) & (c)
c) Meta class WBUT 2012, 2016] b) (c)& (d) c) (a), (b), (c)& (e) d) (a), (b), & (e)
Answer: Answer: (d)
a) Access Specifier: Refer to Question No. I of Shori Answer Type Questions
ns.
2. Which one of the following is a valid declaration of an applet? wBUT 2007
b) Wrapper elass: Refer to Question No. 6 of Long Answer Type Questions. a) public class
MyApplet extends java.applet.Applet (
b) public Applet MyApplet{
c) public class MyApplet extends Applet implements Runnable
)Meta class: Refer to Question No. 2 of Long Answer Type Questions d) abstract class My Applet extends java.applet.Applet (
Answer: (a) & (c)

3. Exception is defined
in.... .package. WBUT 2007, 2009]
a) java.util b) java.lang c) java.awt d) java.iio
Answer: (b)

4. The concept of multiple inheritance is implemented in java by WBUT 20O7]


a) extending two or more classes
b) extending one class and implementing one or more interfaces
implementing two or more interfaces
c)
d) All of these
Answer: (6) & (c)

5. Which of the options matches the following line: WBUT 2008]


he scheme for representing the relationships between classes
a) method b) inheritance c) message d) polymorphism
Answer: (6)

. If a base class has a method defined as WBUT 2009]


abstract void method( );
is mandatory in the derived class?
nich of the following lines b) int method ( ) {return 0;}
a) void method() (
d) private void method () {}
c) void method (int i) ()
Answer: (a)

oOPM-57
0OPM-56
POPULAR PUBLICATIONS OBIECT ORIENTED PROGRAMMING
correct
declaration of an abstract method that is intendes
d
be o 12. narrowest valid return Type for method A in line 3?
What is the
public class Returnlt WBUT 2013]
7. What is the WBUT 20101
public? b) public abstract void add (O0
a b s t r a c t void add () d) publicvirtual add ()
a)public etu Type method A (byte x, double y)/"Line
c) public
abstract add () 3
Answer: (a) Return (long)x/ly 2;
8. Consider the class
WBUT 2011
1. Public class Over {
2. public int test (int a, int b)
a) int b) byte c) long d) double
Answer: (d)
3. .
here
4. Il add
5. 13. Runtime binding occurs [WBUT 2014]
overloaded methods would be legal is added at line 472 a) when method overloaded
Which of the following b) interface only
a) Public float test (float a, float b) {} c) class and interface
d) only subpackage
b) Public int test (float a, float b) {} 'Answer:(C)
c) Public int test (int x, int y) {}
d) Public float test (int a, int b) {) 14. Abstract class is used for WBUT 2014]
Answer: (a) & (b) a) inheritance only b) instantiation only
c) both (a) and (b) d) uselesss
signatures in interface?
9. Which three are valid method an
WBUT 2013] Answer: (a)
1. private int getArea();
2. public float get Vol(float x);
15. What is an example of polymorphism? WBUT 2016]
3. public void main (String D args); a) Inner class
4. public static void main (String args); b) Anonymous classes
5. boolean setFlag (Boolean 0 test); c) Method overloading d) Method overriding
a) 1 and12 b) 2, 3 and 5 c) 3, 4 and 5 d) 2 and14 Answer: (c)
Answer: (6)
16. can be represented by
The relation between classes [WBUT 2016]
10. classA WBUT 2013] a) polymorphism b) method c) message d) inheritance
Answer: (d)

17. Method overloading


protected int method 1 (int a, int b) occurs only when WBUT 2016]
a) the names and the type signature of two methods are not identical
of two
Return 0; b) the
the names and the type signature methods are identical
c) names and the return types of two methods are identical
d) only the names are identical
Which is valid in a class that extends class A4? Answer: (b)
a) public int method 1 (int a, int b) {regurn0;)
b) private int method 1 (int a, int b) {return 18. Final is
c) public short method 1 (int a, int b)
0;} useful1 WBUT 2017]
a to protect a method from overloading
d) static protected int method 1 (int a,{return 0;)
int b) {return 0;) b) to protect a class from inherit
Answer: (a) implementing
to protect a interface from
d) none of these
11. Which is valid declaration within
a
an interface? WBUT 2013 Answer: (a) and (b)
a) pubic static short stop =
23; b) protected short stop = 23;
c) transient short stop = 23; 19. Dynamic method dispatcher is useful for
Answer: (a) d) final void madness (short stop) WBUT 2017]
a) to resolve method override
D) to resolve multilevel inheritance annomaly
0OPM-58 0OPM-59
POPULAR PUBLICATIONS
OBIECTORIENTED PROGRAMMING
to resolve multiple
inheritance annomaly ncapsulation. oojec-Oriented programming languages rely to
c) of these
ate high-level objects. Encapsulation is heavily on
encapsulato
d) none
hiding.
closely related to abstraction and into
Answer: (a)
Customer. waiter and kitchen are three shielded kample.
method at all objects in the 'cup or co
20. An abstract class can contain no
c) Variable d)
WBUT 2017
None
stomer and Kitchen do not know each other. The
waiter is the intermediary
De
a) True b) False of these those two. Objects
cant see
each other in an Object Oriented world. The "hatch enab
Answer: (b) them to Communicae and exchange coffee and
Fncapsulation keeps computer systems flexible.money.
The business process can
Short Answer Type Questions The customer does not care about the coffee brew process. Even the waiter cnanec
does not
This allows the kitchen to be reconstructed, is only the 'hatch' remains the same. it is caic
binding.
e
ossible to change the entire business process. Suppose the waiter will brew corree
1. Differentiate between Early binding and late WBUT 2010 himself. The customer won't notice any difference.
OR,
What is the difference between static binding and dynamic binding? WBUT 2011 Encapsulation enables OO experts to build flexible systems. Systems that can extend as
Answer: yourbusiness extends. Every module of the system can change independantly, no impact
to the other modules.
Late Binding:
At run time, when it is known what class objects are under consideration, the

appropriate version of function is invoked. Siice the function is linked with a Polymorphism:
particular class much later after the compilation, this process is known as late In object-oriented programming, polymorphism (from the Greek meaning having
multiple forms") is the characteristie of being able to assign a different meaning or usage
because tlhe selection of the
binding. It is also known as dynamic binding to something in different contexts specifically. to allow an entity such as a variable,
appropriate function is done at run time dynamically. Dynamic binding requires function, or an object to have more than one form. There are several di fferent kinds of
use of pointers to objects
which function will be called. polymorphism.
binding is implemented when it is not known
Late
a given name may be allowed to have different
forms and the program
1) A variable with
though early binding is faster than late binding. can determine which form of the variable to use at the time
of execution. For example. a

variable named USERID may be capable of being


either an integer (whole number) or a
wants to allow a user to enter a
Early Binding: string of characters (perhaps because the programmer
The overloaded member functions are selected for invoking by matching user ID as.either an employee number -
an integer or with a name a string of
at the compile time and, to distinguish which form is being
handled in
arguments. The compiler knows this information characters). By giving the program way
a
therefore, compiler is able to select appropriate function for a particular call at
be recognized and handled.
statie each case, either kind can also on the parameters it is given.
For example,
itself. This is called early hinding or static binding
or
compile time ) A nanmed function can vary depending
to seek a match against
linking. This is also known as compile tine polymorphisni iT given a variable that is an integer,
the function chosen would be
it would seek a match against a
the variable were a string.
Early binding determines execution path at compilation and late binding allow a list of employee numbers; if
be known in the program by the same
for dynamic execution at runtime. ist of names. In either case,
both functions would
as overloading.
for example: In a native Win32 code environment (i.e.. non .NET), late binui is sometimes known
all the dme. This type of polymorphism
which has properties like wheel
size, engine size, gas tank size,
could refer to the use of a DLL library vs. the use of a static librar YOu drive an automobile, implementation of
rererences in a static library can be determined at compile time. dut The automobile
arVe
you Sa concrete
dna other properties. sliding doors, logo type. cd
rererences in a DLL (dynamic link library) are not determined later u
run
interface. It has additional features, ike that are specific
the automobile
roof lever location,
or
oner various properties
time. Changer slot count, moon nave certain behaviors like
to the make/model of the
car. In addition, automooile may be specific to an
behaviors that would
wheel, and other
trunk, turn
2. What
Answer:
arethe main characteristics of oOP Language? Explain each. [Wou pen/close door, open
automobile. would be the base class
Automobile
using the automobile example, For instance.
Encapsulation: entity. For O0 programming,
manufacturer woula nave
ns
Own implementation.
Volvo uses diesel
n it is the process each automobile implementation.

programming, elements to createa ne


of combining nd which is in is own
technology,
example, a procedure is a type ofencapsulation because it combines a series on onda has V-Tec 0OPM-61
instructions. Likewise, record
a complex data type, such as a or
clas
OOPM-60
POPULARPUBLICATIONS
OBIECT ORIENTED PROGRAMMING
More importantly, you may add an added i.
4. What do you meant by 'Dynamic Method
engines, which is the TDI echnology.
make/model implementation, such as Car T
of Dispatch'? WBUT 2013]
the
detail between automobile and
Answer:
, or

Suv super types, to provide more relevant information. Refe fo Question No. 11(a) of Long Answer Type
Questions.
Inheritance: sWhat will be the output of the following
with each class A (void show0(system.out.println programme code? EXplain ARIT
Different kinds of objects often have a
certain amount in common
("Inside show of A"):}} 2013]
Mountain bikes. road bikes, and tandem
bikes, for example, all share the characteris class B extends A{void show () {super.show ():
of bicycles (current speed, current pedal cadence, current gear). Yet each also define system.out. printin ("Inside show of B"):)
es class demo {
have two seats and two c
additional features that make them different: tandem bicycles sets
of handlebars; road bikes have drop handlebars; some mountain bikes have an addition
ional
public static void main (String args D)X
lower gear ratio.
Aa1 new B0; a1.show();
chain ring. giving them a
inherit commonly used state and behavior
Object-oriented programming allows classes to Answer:

from other classes. In this example, Bicycle now becomes the superclass
of MountainBike, RoadBike, and TandemBike. In the Java programming language, each
Output:
Inside show of A
class is allowed to have one direct superclass, and each superclass has the potential for an Inside show of B
unlimited number of subclasses: Bicycle In the line ' A al = new B()' class A is reference but the object is o f class B.

The 'super.show calls first the show () method of class A from class B.

6. Explain Dynamic Method Dispatch with suitable example WBUT 2015]


Answer:
Refer to Question No. 11(a) of Long Answer Type Questions.
7. What is function overloading explain with example. WBUT 2017]
Answer:
its data
If a class has multiple methods having same name but different in parameters.
Method Overloading. If we have to
MountainBike RoadBikee TandemBike type and the order of the parameters, it is known as
the methods increases the readability
perform only one operation, having same name of
A hierarchy of bicycle classes. called is decided at compile-time. based
of the program. In this case, the actual method
The syntax for creating a subclass is simple. At the beginning of your class declaration, or instance. the methobd
on the number, types and order of arguments.
use the extends keyword, followed by the name of the class to inherit from: so that you can pass int as well
as Strings, and it wil

class MountainBike extends Bicycle { System.out.println() is overloaded,


a different version of the method.
I new fields and methods defining a mountain bike would go here call time polymorphism. In this example add()
11) Overloading is an example of compile
method is overloaded.
This gives MountainBike all the same fields and methods as Bicycle, yet allows its coac Example
to focus exclusively on the features that make it
unique. This makes code for you class b{
subclasses easy to read. However, you must take care to properly document the state an public void add(int i, int j){
each superclass defines, since that code will not appear in the source tie is passed.
behavior that
each subclass.
) this method will be called
when 2 parameters

int n =

i+j:
3. Explain with the help of an example, how java gets benefited by rface? System.out.println(n);
usingInterta
WBUT 2012, 2015,
2016)
public void add(int i, int j. int k)
Answer:
Refer to Question No. 4(b) of Long Answer Type Questions
0OPM-63

0OPM-62
POPULAR PUBLICATIONS OBIECT ORIENTED PROGRAMMINC
when 3 parameters
is passed. Person is concrete class that
a
l ii) this method will be called Here represents a person, while
int n = itj+k; ete class that represents the details of a person who is
Employment aly
System.out.println(n): them together, you would have everything necessary toemployed. If
define and you cou an
implement
Employee class.
ExCept in Java you can't. Inheriting implementation from mo than
E Derclass multiple
int ){
public void add(int i, int j, int k, one
implementation inheritance IS not a feature of the language.
called when 4 parameters is passed. allows a class
i i ) this method will be to have a single superclass and no more.
int n= itj+k+l; On the other hand, a class can implement multiple interfaces. In other words, ava
suDports muluple intertace inheritance. Suppose the PersonLike interface is:
System.out.println(n)
publ1c
1nterIace
PersonLike (
public static void main(String [}args){ string getName);
bbl = new b(); int getAget)i.

bl.add(1,2.5); / ii) is called

and the EmployeeLike interface is:

output: 8 public interface EmployeeLike


float get Salary):
java.util.Date getHireDate () ;
LLong Answer Type Questions
If Person implements the Person-Like interface, and Employment implements an
1. a) How Java implements multiple inheritance? Justify your answerWBUT
with a 2005]
small EmployeeLike interface, it's perfectly acceptable to write:
public class Employee implements PersonLi ke, EmployeeLike
example.
OR, // detail omitted
i) Multiple inheritance can be performed in Java. Explain how?
i) Write a Java program in support of your views. WBUT 2011] Here there i s no explicit superclass. Since we are allowed to
OR, specify a t most one superclass, we could also wT i t e :
Explain whether java supports multiple inheritance or not. [WBUT 2013] public class extends Person implements PersonLi ke
mployee
b) What is method overloading ? WBUT 2005, 2008] EmployeeLike
OR, detail omitted
Explain Function overloading with an example. WBUT 2013]
How is it different from method
over-riding? WBUT 2005, 2006
of
OR, We would
the
need to write the
implementation of PersonL1lke
implementation
1s taken care f
EmployeeLik, but
through t h e
Differentiate between Method overloading and
Method overriding.
[WBUT 2009, 2010, 2011, 2013, 2015] e r son superclass . Alternatively we might write:
c) Write how to prevent method over-riding. WBUT 2005, 2008] public, class Employee extends EMpioYment 1mpiements PersonLike,.
Answer: EmployeeLiket
/7 detail omitted
a)When Sun was designing Java, it omitted multiple inheritance or more precisely
mutiple implementation inheritance on purpose. Yet multiple inheritance can be user
This is the opposite situation: the EmployeeLike interface Is taken care of through the
particularly when the potential ancestors of a class have orthogonal concerns. This atice but we do need to write an implementation for PersonLike.
mployment superclass,
presentsaility classthat not only allows multiple inheritance to be simulated, but also
has other far-reaching
applications. Java does not support multiple implementation
inheritance, but
does support multiple
remark that Java does not
Have you ever found yourself nterface inheritance. When you read or overhear someone
wanting to write something similar to:
Support multiple inheritance, what actually
is meant is tnat it does not support
multiple
public class Employee extends Person,
/7 detail omitted Employmernt mplementation inheritance.

b) 1" Part:
his during
type of polymorphism is achievedwant to the program. Programmers
writing ofMethods are
impose. as well
as constructors
awar
are of the polymorphic nature they
0OPM-65
OOPM-64
POPULAR PUBLICATIONS OHJECT ORIENTED PROGRAINING

within the class body. method/constructor have


Each oVERLOADING oVERRIDINGGhe
can be made polymorphic This phenomenon is known as
Same will pas>cd t |
but with different arguments. n e type of reference
name
said to be an overloaded version of the 0adinp
of
ne reterence variable. It is also called
Parameterized
constructors are
default Dynamic Method Dispatch.
constructor. ENmple:

The rules of overloading are: class b Example:


should vary in their numbers and public void add ( int i int il
class at
T h e parameters of the methods/constructors data- int n 1+);
public void display ( )
1t 1S
type. while overloadino System.out.println(
methods/constructors is not considered System.out.println (n);
.The return type of the firest class method)
public void add ( int i int j int
class definition
For example let us consider the following
k) class overiding extends a
public class Overloada int n 1t)+k

int Y)} System. out. println(n); public void di splay (O


public void sum ( int x,
Ystem.out.printLn 1t 1S

i int j method
public vold acid (1nt int| Second class
k int1)
The valid overloading methods in the same class are:
int n 1+)+k+l; void mair(String
public s t a t i c
1. Change in data type of the arguments System.out .print in(n); lanil)
public void sum ( float x, float y) ) Overiding obj new overiding ():
public void sum( flOat x, int y)t}
public s t a t i c void main (String
2. Change in the number of arguments o b j . d i s p l a y( ) :
Daa
public void sum (int x, int y, int z) ( b bi new b )
3. Return type is not considered. Hence the following line is not a valid bl.add (1 2 5);
overloading. l is a Second class method
//public int s um ( int x, int y) ( ) Oulpul:
Although we are using the same name in the overloaded versions but actualy each Lpil:8
method is different and is unique on it's own. That is why, often overloading is not
the method as final.
considered as polymorphism. The return type has nothing to do with the implementation c) We can prevent overriding in Java by declaring
details of a method, hence it is not considered during overloading
class' and interface'?
2. What are the differences between 'abstract
wBUT 2005, 2007, 2009, 2010, 2011, 2013]
2nd Part:
OVERLOADING OVERRIDING Answer: Interface
i) Method overloading is defining several| i) Method overriding is when Abstract class
a
child class 1. An abstract class can containAn intertace can have only
abstract methods.
methods in the same class, that accept different redefines the same method as a parent class,
mplementation of some inethods apart
and types
numbers of parameters. In this with the case.| same parameters. Irom the abstract methods. This makes
the actual method called is decided at compile-| For example, the standard Java class
time. based on the number and types of java.util.LinkedHashSet extends read only clasS.
abstract class tomake a inheris class that mplements or inherits an
an adstract
For instance A class that extends or
arguments the methodjava.util.HashSet. The method add) s| .
same classntertace need
not be in the same hierarchy in

class must reside in the


System.out.println() is overloaded, so that you| overridden in LinkedHashSet. If you havea abstract class hich the intertace belongs.
can pass ints as well as Strings, and it will call| variable that is of type HashSet, and you cu hierarchy where the parent
a different version of the method. its add() method. it will call the appropriat helongs. be
liltedeaSIi
ultipie classes can implement

whether
of add(). based on A n e w abstract class caot is not a mandate that these
implementation Into class hierarchy. For exampie
o
eee.as
same hierarchy in which
is a HashSet or a LinkedHashSet. 1his a
the
ne
sme
s e s wil
be in the
classes inherits or extends interface belongs.
called pol ymorphism. the abslract
class needshe
ime bstract class, then
11) Overloading is an
example of compile time ii) Overriding is an example or
ro un nierirchy lhe

polymorphism. polymorphism. The JVM does not Kn b e placed higher up his Can disturh
classes.
be called bove lhese two OOPM-67
which version of method woula
0OPM-66
OBIECT ORIENTED PROGRAMMING
POPULARPUBLICATIONS
An interiace in Java
supports multiple inheritance. Unlike classes.
Interface brovide any concrete
an
interta
Abstract class implementation. Rather the implementation IS
a

hierarchy. as this will force all


the |
not
which implements the interface. po
the class
abstract
class n
the the keyword
use
implementing a
descendants to extend new

extra
o declare an nieriace we interface. To have a class
class.
implementation
This may
involve
overhead
some

tor these nterface the keyword mplements is used.


descendants. can mplement multiple Che salient features of an interface are:
A class can at most extend or inherit o n e A Class
at t h e
same ume can extend a clae
interfaces . Since methods in an intertace do not provide any concrete implementation. tne s

Single parent. This is known as Single and


any concrete implementation.
or
no need to instantiate an object on the reference of an interface. Hence the n e
directional inheritance.
This mixed type or innertance helps us to
design more flexible data structures. This is operator is not used in conjunction with an interface.
All methods of an interface are automatically public and abstract For that reasod
known as multi-directional inheritance 2. is not necessary to supply the keyword public and abstract when declaring a metno

in an interface. An interface can have only abstract methods.


and method-overloading in JAVA.
3. Compare between method-overriding 3. Variables declared in an interface are static and final by default.
WBUT 2006, 2009 An intertace can extend other interfaces using the extends keyword
Hence between
4.
interfaces the inheritance relationship is again a single inheritance type
Answer
1(b) (2"" Part) of Long Answer Type Questions.
the
to override all
Refer to Question No. A class can inherit from multiple interfaces. Such a class needs
methods that come from all the interfaces it has inherited.
What isthe
4. a)Discuss the of super keyword
use in JAVA? WBUT 2006]
interfaces. WBUT 2006, 2007] Interfacel.java
b) various forms of implementing package matrix.ad.edu;

Answer publiC intertace Intertacel

a) The keyword super is used to access methods/variables of the parent class.


ex void displayl0:
public class A
public String getName (){ Interface2.java
package m a t r i x . ad.edu;
public inter face Inter face2

public class B extends A void di splay2 )


public String getName (){
ImplementClass.java
package matrix. ad.eduj Interface2
implements Intertacel,
class ImplementClass
If you the method getName of class A inside class B you cannot do
want to access public
U argsS)
directly because the compiler would get confused. you need not create an object of A ubiiC static void main ( S t r i n g
since itS already available. A t this point you can use super
0;
super. getName() is enough to call the method of the parent class. il new Implementclass
nter facel
=

Actually there are three uses of super keyword. Overriding through dynamic linking Implementelass();

D Super keyword is used to call immediate parent. i2 = new


ertacel
linking
2)Super keyword can be used with instance members i.e., instance variables and OVerriding through dynanmic
instance methods. il.display)
3) Super keyword can be used within constructor to call the ent 12. display )
constructor o pa
class. void displayl ()
public
( "Display
of Inter facel"):
Ystem.out.println
oOPM-69

0OPM-68
OBIECT ORIENTED PROGRAMMING
POPULAR PUBLICATIONS s tem. out.printin"interface1
+ is extended byinter face2 " )%
also needs to be impleme
()
public void display2 public s t a t i c vold main (String [] args)
Interface2") ;
"Display of
System.out.println(
i xedDataType
Mi
mxdtyP new
MixedDataType ();
mxdtyp.display1 ();
mxdtyp.di6play2 ();
mxdtyp.display3 ();
Output
Display of Interfacel
Display of Interface2

5. a) What is an Interface? Implement Interface in java with a simple code. b) In object-oriented programming (OOP), inheritance is a way compartmentalize
to and
whicn
WBUT 2007, 2009] reuse code by creating
collections of attributes and behaviors called objects ca
b) Explain inheritance with its types. WBUT 2007, 2009, 2010] based on previously.created objects.
OR, The derived class inherits some or all of the traits or properties
from the base class.
level.
A
How many types of Inheritance in java7
wBUT 201] class can also inherit properties from more than one class or from
m o r e than o n e A
Answer: derived class with only one base class is called single inheritance and one with severa
a) An interface in Java supports multiple inheritance. Unlike classes. an interface does the
combine
base classes is called mulliple inheritances. Multiple inheritances allow
us to
not provide any conerete implementation. Rather the implementation is provided by a n e w classes. Now,
in
features of several existing classes as a starting point for defining
class. which implements the interlace. from another derived clas. Suppose a
case of multilevel inheritance, a, class is derived
To declare an interface we use the keyword nterlace. To have a class class for another derived
interface the keyword implements is used. iplementing an class is .derived from one class, which in turn serves as a base
traitss
the other hand. the
package matrix.ad.edu; class. So, here the features inheriting continue level by level. On
This process is known as
interface inter facel of o n e class may be inherited by more than one class.
need to apply two o r m o r e
hierarchical inheritance. There could be situations where we

void displayl () This type of inheritance is called hybrid


types of inheritance to design a program.
interface interface2 extends inheritance.
interfacel Different types of inheritance are shown below with diagrams:
void
di splay2 ():
class Extra

public void display3 ()


Single inheritance Hierarchical inheritance Multiplee inheritance
System.out.println("Display of the extra
class");

public class MixedDataType extends Extra


public void display2
implements intertace
(
System.out.println("interface2 is
implemented" ):
public void
isplay1 ()
Multilevel inheritance

Hybrid inheritance
0OPM-71
OOPM-70
OBIECT ORIENTED PROGRAMMING
POPULAR PUBLICATIONS
irterface
of inheritance java
supports a r Stack lerfece
6. What is inheritance? How many types Queue
Discuss it. Given a method that does
not
declare any exXception, can I overrire? that size, long
method in a to throw an exception?
subclass WBUT 2007, 2017 site bong
O push)
Answer: insertO
pop)
1" Part: remove0
The term inheritance in object oriented programming implies a parent-child relatian
between two or more than two classes. In Java, inheritance is achieved by using the onship
extends keyword.
Illustration
The diagram shown below illustrates a parent-child relationship between two classes. cimplemertaionClass»
The class Parent has two private instance variables and a set of public get set methods MyClass
which provides a way to access the variables outside the class. eth ds,
O insertO
The class child inherits the properties of the parent except the private instance variables
popo
That is, the child class has an automatic access to get set
the methods of the parent class. pushO
Apart from this the child class can also define it's own attributes. Here the child class
o remove0
defines a boolean variable and the corresponding methods to access the variable.
This inheritance relationship is often referred to as 3rd Part:
"There IS-A relationship between' child and parent" When you extend a class, the subclass inherits the methods of the super class. You can

the subclass. The


replace (override) these inherited methods by declaring them again in
method in the subclass is called the overriding method and the method in the super class
Parent
rule for declaration of these
is called the overridden method. -Java has a specific
n a m e : Strin9 method to throw checked
overriding methods. You cannot declare an overriding
the super class. The overriding
getage exceptions, which are not declared in .the method in
an overidden method is throwing
getName0 a
o setAge) method can do any of the following things when
o setNemeo checked exception:
throw any exception.
The overriding method may decide not to
that is a subclass of the exception thrown by
The overriding method may throw exception
the overridden method. class of the
Chlld throw exception that is
a super exception
The overriding method cannot
sDependat: boolean method.
thrown by the overridden understand Figure 5.5 illustrates these rules. It
isDependat)
These rules are simple to with an example. to throw an IOException. The
setDependeto which declares
shows a Base class with aMethod() subclasses of the Base
and lllegallwo classes are all
Derived1, Derived2, IllegalOne, Base class.
2d Part: overrides aMethod() of
Refer to Question No. 5(b) of Long Answer Type Questions. class. Each of these classes

7. How two methods have same signature? Brietly


describe the method overriding
inheritance? What does the
does not support multiple
with example. Why Java [WBUT 2008]
super keyword do?
Answer: same signature ir there is a parent-child relationship
have the
In Java two methods can
between two classes. methods be
witnoverriding. Only
can

The actual flavor of polymorphism comes


overrIdes m e t h o d s of a parent class. By inheritance
child class
overridden. Usually the
0OPM-73

0OPM-72
POPULAR PUBLICATIONS
OBJECT ORIENTED PRoGRAINING
methods of a parent class is always available in the child class. The child clo key word is used
The hio. to refer the
parent
changes the implementation details. just In sonme cases he
child class will constructor or method in pau child
relathan overriding these
rather
reler to
imethods explicitly in the the parent consstr
is. thal il should be lirst class
The basic rules for overriding a method are: super
statement to be called in body.
The only
the child elass
resurn tion
A method overriding is possible only when there is a parent-child relationeL: c o n s t r u c t o r .

n
between two classes. The overriding method should always be in the child class
The overriding method in the child class and the overridden method of
the ho. ect the following code for
class must be same in terms of the number ot parameters, tne data type and arent public class Figure overloading method: WBUT 2009, 2010]
the ret
eturn
ype as well.
Public String draw (String s)
Let us consider the following programs
Class Parent ReturnFigure Drawn"
public String format
( String inputstr)
public vold draw (string s) )
public void draw (double £)
Answer:

if(" public class Figure (


.equals (inputstr) || inputStr == ul1) public String draw (String s) (
return Cannot format Blank/Null String *; return "Figure Drawn";

return ("#"+inputstr+"#"):
public void draw(String s, double 'f) ( )
1 corrected overlading
class Child extends Parent public void draw (double f ) )

performs a different operation by overriding the method */


public String parent 9.
format (String inputstr) What do
you mean by parameter passing? What is call by value and call byy
rererence? Write down two programs to define call by value and call by reference.
if(" .equals (inputStr) || inputStr WBUT 2014]
==
null)
OR,
return Cannot a) What do you mean by parameter passing?
format Blank/Null string "; b) What is the difference between call by value or pass by value and call by
return
"<"+inputStr. toupperCase()+">") ; rererence or pass by reference? Explain. WBUT 2015]
Answer:
" Part:
Parameter passing is the mechanism used to pass parameters to a procedure (subroutine)
Multiple inheritance often makes a class
increase in the system then the hierarchy very complex. If the number of or function. The most common methods are to pass the value of the actual parameter (cal
will be lots of child classes relationship becomes very difficult to maintain. Asclasse b' wilue). or to pass the address of the memory location where the actual parameter is
addition of an extra class in.inheriting different properties of their parent classes. tnerc stored (cull hy reference). The latler allows the
method
to the value of
procedure change
the hierarchy can
hierarchy itself. If not properly handled cause severe n the parameter, whereas the former method gurarantees that the procedure will not change
the relationship
distortion to the enu Other methods
erroneous results. That's
why Java does not between the classes can gv the value of the parameter. more complicated parameter-passing
been devised, notably call hy name in Algol 60. where the actual parameter,is re-
have
Java
absolutely support multiple inheritancesupport multiple inheritance in class.
in terms of Cvaluated each time it is required during execution of the procedure.
class
we
only to avoid ambiguity problem. In interface Interfacé. We can
extena
don't get any we have to define the
JAVA this thing isambiguity. In ct+ it is big problem with functions:
improved by introducing Interfaces. multiple inheritance
0OPM-75
0OPM-74
OBIECT ORIENTED PROGRAMMING
POPULAR PUBLICATIONS S y stt
out.printinbefore change " +op.data);
e m .

change p);//passing object


Op. out.printin"atter change "+op. data);
2d Part:
In programming.
there are two ways
to pass arguments to
a method, call.
call-by-value and S y s t e l . O u t .p r i

call-by-re ference: copy or h e argunment is storod


a .

W h e n we have a call-by-value parameter, nto


formal parameter. In this case, anv h
the memory location allocated for the
will not affect the val ges Output:e
before Change 50
inside the method after Change 150
made to the formal parameter
the calling method.
argument back in
the memory address of the Explain abstra
When a parameter is
call-by-reference, argument s 10. What are
the diterent characteristics of abstract keyword? WBUT 2015]
an alias for the aro
the formal parameter a program.
passed to the method, making
through
inside the method class
made to the formal parameter will be
This means that changes Answer:

when control is returned to the


reflected in the value. of the argument 1s Part:
can be used on classes and methods. A class declared
with
the
function. The abstract Keyword the "abstract
cannot be instantiated. and that is the only thing
abstract" keyword.
does. Example ot declaring a abstract class:
3 Part call method passing
keyword
call by reference. It we a
abstract CalendarSystem (String name)
;
There is only call by value in java, not the called then, its methods may also be declared abstract.
value, it is known as call by value. The changes being
done in method, isIS 1ot When a class is
declared abstra t,
This is thne
a definition.
affected in the calling method. a method is
declared abstract, the method can not have
When method:
abstract
effect the abstract keyword has
on method. Here's a example of a
only int getperson_id (Strlng name) ;
Example of call by value in java abstract structure. without
abstract methods are like skeletons. It defines a
class Operation{ Abstract classes and
int da ta=50; any implementation. not necessarily
Abstract class does
void change ( i n t data) classes can have abstract methods.
data=data+100;//changes will be in the local variable only Only abstract
to be all abstract.
require its methods for the purpose of
extension

abstract keyword are solely


Classes declared with the given below:
public static void maiin (String argsl)
(inheritance) by other
classes. The characteristics abstract class
of
are
references of Abstract
operation op=new operation ( instantiated, but pointers
and
Abstract class cannot be
System.out.println ( "before change " *op. d a t a ) ;
)
class type can be created. virtual
op.change (500); normal functions and
variables along with a pure
change "+op.data) Abstract class can have
System.out.println("after 2)
function. so that its derived classes
can use

mainly used tor Upcasting,


3) Abstract classes are
Output: its interface.
all pure virtual functions, or
before change 50 an Abstract
Class must implement
after change 50 4) Classes inheriting
Abstract tvo.
else they will become
Another Example of call by value in java
ln 2 Part: functionality of object and let
case of call by reference originalof value is changed if we made changes in the called default an
is to specity the
method. If we pass object in place any primitive value, original value will be changed. he purpose of an abstract class
implement that
funetionality. Thus,
it stands as a n abstraction
In this example we are
passing object
as a value. Let's take a simple example its sub-classes to explicitly
extended and implemented by the corresponding
sub-classes.
Class Operat1on2t
int data=50;
ayer that must be of using an abstract class iS the following. We declare a n abstract
void A Sample example
change (Operation2 op) class, called Instrument:
op.data=op.data+100; //changes will be in the instance variaDi Instrument.java:
Dstract class Instrument
publiC static void
main (String args U)U
operation2 op=new Operationz): oOPM-77
OOPM-76
POPULARPUBLICATIONS
OBIECT ORIENTED PROGRAMMING
protected String nanè;
abstract public void play()
ut.println "An electric*
name

i s rocking! "); numberOfStrings+"-string


As we can observe. lnstrument object contains a
an
that must be implemented by a sub-class.
field name and a
method ealled nlau
y . We
Finally
create a new class
called Execution that contains
y Executon. j a v a :
Nexi, deline sub-class called Stringednstrument that extends the
a
single main methoa:
we a
Instrucs r t main.
and adds an extra
StringedInstrument. java:
field called numberOfStrings: class imp
import main.
1 class
java.musiC.ElectricBassGuitar;
main.java.music.ElectricGuitar ;
abstract
C Execution (
class StringedInstrument
protected int numberofStrings;
extends Instrument ( Ph1ic static void main (String[)
PcticGuitar guitar args) =
new

Finally. add o1ectricBassuitar


Ele bassGuitarElectricGuitar (); =
we

Siringedlnstrument.
two more classes
that implement the
functionality guitar.play() ElectricBassGuitar O; new

calledElectricGuitar and ElectricBassGuitar of a bassGultar.play ();


definition of these newly added classes is shown below: accordingly. The guitar new E l e c t r i c G u i t a r (7) :

ElectricGuitar.java:
public bassGuitar new
ElectricBassGuitar (5) ;
class ElectricGuitar extends guitar .play();|
public ElectricGuitar() StringedInstrument (
super (): bassGuitar.play ();
Chis.name = "Guitar";
In this example, we create two different instances of an
this.number0EStrings = 6; ElectricGuitar and an
ElectricBassGuitar classes and we call their play methods. A sample execution of the
public aforementioned main method is shown below:
super)
ElectricGuitar (int nunberOfStrings) An electric 6-string Guitar is
rocking!
this.name = "Guitar"'; An electric 4-string Bass Guitar is
An electric 7-string Guitar is rocking! rocking
An electric 5-string Bass Guitar is rocking!
this.number0EStrings nuunberOf Stringss; =

override
public void 11. Write a super class interface employee has name and idhasnumber. Write
play () ( manager and labour derived from employee class. Manager class member data
System.out.println("An
+name electric "

numberOfStrings +"-string
g-function
member data q ficationOvertime
andDailywage, and manager allowance and rank labour class has
and Grade. WBUT 2017]
"
is " Answer:
rocking ! ") ;
Class Employee
ElectricBassGuitar.java
public class
int id;
string name;
ElecttricBassGuitar
public ElectricBassGuitar() ( extends StringedInstrument
super ( ); Lass manager extends Employee
this.name =
"Bass Guitar";
this.number0fStrings = 4; string qfunction;
string fication;
publiç
super():ElectricBassGuitar (int
int allowance;

this.name =
"Bass
numberOfStrings) ( int rank;

Guitar"
this.number0f Strings = ass labour extends Employee

Override
numberofStringii; int Dailywage:
int overtime;
public void
play () char Grade;

Class A
0OPM-79
OOPM-78
POPULAR PUBLICATIONS
OBIECT ORIENTEDPROGRAMMING
(string [) args) child c (Child) p
main
public s t a t i c void
c.display ();

12. Write short notes on the following:


a) Dynamic method dispatch WBUT 2008, 2017 Explanation

b) Interface [WBUT 20141 Parent P new Child():


c) Inheritance WBUT 2014 During compeme, p is the object reference of class Parent. But during executíon of the
d) Encaps ulation
e) Co-Varient Return
WBUT 2014 nrogram, it binds to an object of sub-class Child.
[WBUT 2015] Child C .(child)p;
Polymorphism
g) Abstract Class
WBUT 2016] Finally,
WBUT 2017] . c.display (); executes and an output is given like this
hi) Method
Dynamic Binding
overriding with example
WBUT 20171
Answer:
WBUT 2017] In Child
a) Dynamic method dispatch:
Dynamic method dispatch is a concept which comes during overriding a method. This i
The overridden version of display() is called. This is known as runtime polymorphism
as the
as the
call the method is decided
to during the execution time of the program
also known as runtime polymorphism. The actual 1lavor of polymorphism comes with dynamic linking is done only at that time.
overriding. Only methods can be overridden. Usually the child class overrides methods
a parent class.
By inheritance methods of a parent class is always available in the of b) Interface: Refer to uestion No. 5 of Long Answer Type Questions.
class. The child class just child
changes the implementation details.
c) Inheritance: Refer to Question No. 2 of Short Answer Type Questions.
For example let us consider the following class definition
Parent.java d) Encapsulation: Refer to Question No. 2 of ShortAnswer Type Questions.
public class Parent

public void e) A covariant return type is a method return type that, in the superclass's methood
display ()
declaration, is the supertype of the return in the subclass's overriding method declaration.
System. out.println(" In parent"); Lising 4-21 provides a demonstration ofthis language feature.
ADemonstration of Covariant Return Types
Class SuperReturnType
Child.java @override
public class Child extends
Parent Public String toString()

public void display () return "superclass return type"i

System.out.println (" In child"); SuperReturntYpe


ass SubReturnType extends

@Override
Maininherit.java Public String tostring()
public class MainInherit
return "subclass return type";
public static void
main(String[] args)
Parent P =
new class Superclass
Child(); //
dynamic method dispatch
OOPM-80 0OPM-81
POPULARPUBLICATIONS OBIECT ORIENTED PROGRAMIMING
int cix this.x -
SuperReturnType createReturnType ()
int dy this.y
Return new SuperReturnType(); return tioat
Math. Sqrt (dz dx dy dy):
/float distance of
M2 (//0verload detirnitio* (Point p)
Superclass
distance return distance (p.X, p.y);)
Sublcass extends
Class

class Point sD extends point


(doverride
SubReturnType createReturnTYpe () int
2
(1nt X, 3D
oint 3D 1nt y, int z) / / Constructor of Point
super (X, Y);
Return new SubReturnType ()
this.2 z;

publiC clasS CovarDemo / *M3* tioat distance (int , int y, int z) {//Another detinitio
of dis tance

int dx = this.x X;
Public static void main(String[] args)
int dy this.yY
SuperReturnType = new Superclass ().createReturnType (); int dz t h l s ,z Z

Output: Superclass r e t u r n
// type (tloat) Math.sqrt (dx*dx dy dy dz dz) :
System.out.println (suprt) ; return
SubReturn subrt = new Subclass () .createReturnType();
/7 Output: subclass return type /M4*/ floatt distance (Point 3D pt)
System.out.printin (subrt); pt.z) i
return distance (pt.x, pt.Y,

SuperRetumType and Superclass superclasses and SubReturnType and Subclass


subelasses: each of Superclass and Subclass
declares a
createReturnType() method. class PointDistance
vold main (String argSlI)
Superclass's method has its return type set to SuperRteturnType. whereas Subclass's publiC static
new POint (10, 5); //2-D point
Polnt pl
overriding method has its return type set to SubReturnType, a subclass of Point p3 = new Point3D (5, 10, 5) //3-D point
a n o t h e r 2-D pointt
SuperReturnT ype. Point P2
new Point (4, 1);
another 3-D point
Covariant return types minimize upcasting and For
downcasting. example, Subclass's Point p4
new Point3D (2, 3, 4 )
M1 will be reierred
to its
createReturnType() method doesn't need to upcast its SubReturnType instance float do
pl.distance (0,
(p2)
0)
;
//M2 will be referred

SubReturnType return type. Futhermore, this instance doesn't need to be downcast to Eloat dl = pl.distance
°Distance
trom Pi to Origin
="
d0)
SubReturnType when assigning to variable subrt. S y s t e m . o u t .println to pl =" dl)
System.out.println
"Distance rrom p2 M4 will be referred
0, 0);
(0,
) Polymorphism: d
di
p3.distance

p4.distance (P3);
M4 will be
0)
referred
="

trom ps to origind l ) ;
=

Another fundamental object-oriented mechanism in Java is polymorphism. Java allows a


S y s t e m . o u t . p r i n t l n " D i s t a n c e

trom p3 to p4 ="

polymorphism on nethods. Polymorphism, meaning one object and many shapes, is System.out print ln
"Distance

Simple concept that allows a method to have multiple implementations. This Is also
known as nmethod overload. Following illustrates the idea of polymorphism:
W Polymorphism concept /
class point
int x, Y Output: from PI to Origin
11.18034
(int x, int Distance 7.211102
Point
this.X = Y:
y) ( 1 I t is a constructor Distance from P2 to Pl
12.247449

this.y Y: Distance from P3 to Origin 7.6811457


Distance from P3 to P4
*M1*/Eloat distance (int ot
distance
x, int y) // One definition
0OPM-83
0OPM-82
POPULAR PUBLICATIONS
be
OBECT ORIENTED PRoGRAMMING
In the above example, we have
seen how the same method can impleme
mented In
aid show) &
System.out.println("Child's show(").
different ways. The concept of this type
ot method overloading is the same i
as

However, C++ allows operator overloading,


Java does not. C+
I/ Driver class
g) Abstract Class: class M a i n

Refer 1o Question no. 10(2"" Part) of Long Answer Type Questions.


Dublic static void
main(String[] args)
h) Dynamic binding:
i) Dynamic binding also called dynamic dispatch is the process oflinking procedure calt I/ If a Parent type reference refers
to a specific sequence of code (method) at run-time. lt means that the code to be Kecuted / to a Parent object, then Parent's
for a specific procedure call is not known until run-time. Dynamic binding is also kno II show is called
as late binding or run-time binding. Dynamic binding requires use of pointers to obiects Parent objl Parent();
=
new
ii) Late binding is implemented when it is not known which function will be called
obj1.show();
though early binding is faster than late binding. Method overriding is termed as
dynamic binding. // If a Parent type reference refers
// to a Child object Child's show()
i) Method overriding in java: I/ is called. This is called RUN TIME
If subclass (child class) has the method as declared in the parent class, it is
same
I POLYMORPHISM.
as method
overriding in java. In otlher words, if subclass provides the known Parent obj2= new Child():
implementation of the method that has been prOvided by one of its
specific
known as method parent class, it is obj2.show();
overriding.
1) Method overriding is used to provide specific
already provided by its super class. implementation of a method that is
2) Method overriding is used for runtime Output:
polymorphism Parent's show()
Rules for Java Method Child's show()
Overriding
1. method must have same
name as in the
2. method must have same parent class
parameter as in the parent class.
must be IS-A
relationship (inheritance).
Example:
method overriding in
java
I/Base Class
class Parent

void showO { System.out.println("Parent's


show()");
I/ Inherited class
class Child extends Parent
.
I This method overrides
@Override show() of Parent

OOPM-84 0OPM-85
POPULAR PUBLICATIONS
OBECTORIENTED PROGRAMMING
STRING AND STRING BUFFER String s
=
new String ("Stanford");
str += "Lost!!";

ere to use StringBuffer to


perform
you wereet

the same
Multiple Choice Type Questions looks like this: concatenation, you wouid need
that
StringBuffer ("Stanford")
=
str new
StringBufter
1. Consider the following
class definitions: WBUT 20o9 s t r . a p p e n d ( " L o s t ! ! " ) :

class student extends String


Develope lopers usually assume that the first example above is more fficient because they
that the secon ond
example, which uses the append method for concatenation, is
What happens when we tryto compile this class? think more

a) will not compile because class body is not definedd ostly


cost than the first
example, which uses the + operator to concatenate two String objeced
because the class is not declared "public" The +operator appears innocent, but the code generated produces some surprises. Using
b)will not compile because string is "abstract"
c)will not compile StringBuffer for concatenation can in fact produce code that is significantly faster thnan
d) will not compile because string is "final" sing a String. To discover why this is the case, we must examine the generated bytecOde
usir

e)will compile successfully from our two examples.


Answer: (d)
4. Write an application that illustrates variable hiding. Class S declares an instance
2. Which of the following is correct?
a) String temp [] =new String ("j" "a" "z"} b) String temp [] = ("j" "b" *"c'"
WBUT 2010] namedx of type integer. Cass T extends S and declares an instance variable
and
namedx of type String Buffer.
Instantiate both of these classes. Initialize
c) String temp = ("a", "b", "c") d) String temp []= ("a", "b", "c") display the variable named x in such of these objects (use this keyword).
WBUT 2011]
Answer: (d)
Answer
public class S(
Short Answer Type Questions int X

1. What is mutable strings? WBUT 2005, 2015, 2016] void show()


System. Out.println(this.x);
Answer:
Refer to Question No. (String Bufjer) of ShortAnswer Type Questios.
public class T extends S
2. Why is string type array used in the parameter of main () method? [WBUT 2009] StringBuffer x;
Answer: void display ( )
A string type array is used to take multiple arguments in command line. Like java System.out.println(x)
Program Name arg arg2 ary3.
Public class Test
3. Differentiate between String and WBUT 2011, 2012, 2015, 2016] args)t
String Buffer. Fublic s t a t i c void main (Stringll
OR, S s= new S);
How does string class differ from string buffer class? with
Explain example.
WBUT 2015]
Tt= new T ) ;
ln("Value of x in T class");
Stem. out.prir
Answer:
Java
t.display (); of x in S class ");
provides the StringBuffer and String classes, and the String class is used Stem.out.println (
"Value

manipulate, character strings that cannot be changed. Simply stated. objects ot


typ s.show);
String are read only and immutable. The StringBuffer class is used to
characters that can be modified. repre
The significant performance difference between these with a suitable program. WBUT 2014]
two classes is that StringBulter What is String-buffer class? Explain
aster than String when
performing simple concatenations. In String manipulatio code.
Answer: class which is immutable. Both the
character strings are class unlike the String
routinely concatenated. Using the String class. are
oringBuffer class is a mutable
typically performed as follows: concatenat of a StringButter
Class. StringBuffer can be changed
apacity and character string 00PM-87
0OPM-86
POPULARPUBLICATIONS
tion of
dynamically. String buffers are preferred when heavy modification of characte character strings
involved (appending, inserting, deleting, modifying etc). is 9BIECT ORIENTED PROGRAMMING
Strings can be obtained from string buffers. Since the StringBuffer clac 5. toString)

override the equals() method from the Object class, contents of string buffers
ffers not averts to a string representing the
should be data in this
converted to String objects for string comparison. string buffer
if index. is 6. insert(int offset, char c)
A StringlndexOutOfBoundsException is thrown
wrong index in String Buffer manipulations
an not valid when
when using inserts the
f that the string representation of the char,
Note StringButfer class has argument into
Used based on the application need. got many overloaded 'insert'
this string
bun be
Creation of String buffers methods whicn
ca
StringBuffer Constructors
public class StringBufferDemo 7. delete(int start, int end)
Removes the characters in a
substring of this StringBuffer
public static void main(String [] args) (
Examples of Creation of Strings
8. replace(int start, int end, String str)
StringBuffer strBufl new
StringBuffer
=

("Bob")
StringBuffer strBuf2 Replaces the characters in a substring of this StringBuffer with characters in the
=
new
StringButter(100); l/With String. specifiea
capacity 100
ringBuffer strBuf3 =
new
stringBuf fer () ;
//Default
Capacity 16 9. reverse()
The character sequence contained in this
System.out.println( "strBufi1"strBufl) ;
System.out.println( "strBuf2 sequence.
string buffer is replaced by the reverse of the
capacity
strBuf2.capacity ())
System.out.println("strBuf3 capacity 10. append(String str)
strBuf3.capacity ()); Appends the string to this string buffer.
Note that the StringBuffer class has got many overloaded 'append' methods which can be

Output Used based on the application need.


strBuf1 : Bob
strBuf2 capacitty 100
strBuf3 capacity 16

String buffer Functions


The following program explains the usage of the some of the basic StringBuffer methods
like;
1. capacity0
Returns the current capacity of the String buffer.
2. length)
Returns the length (character count) of this string buffer.
3. charAt(int index)
The specified character
of the sequence fer
indicated by the index argument, is returned.currently represented by the string Dui
4. setCharAt(int
index, char ch)
The character at the
specified index of this string buffer is set to ch
OOPM-88 OOPM-89
POPULAR PUBLICATIONS

EXCEPTION HANDLING 6.
1. class Class 1{
OBIECT ORIENTED PROGRANIMING
2. public static void main WBUT 2011]
Multiple Choice Type Questions 3. int total 0; (String args [1) {
1. Exception is defined in . .
4. int []i =
new int [3];
package. wBUT 2007, 20161 5. for (int j=1:j<=i. length;
a) java.util b) java.lang c)java.awt j++)
Answer: (b) d) java.ioo 6. total+ (i ] =j);=

7. System.out.printin (total);
2. public int m1 (int x){ 8.)
int count =1; WBUT 2008 9
What is the output of the
try ( program above?
a) 3
Count += x;
count+ m2 (count); b) 4
6
count++;
d) None. The system will throw an
catch (Exception e) e) None. The compiler will throw a Array Index Out. of Bounds Exception
return count;
{count x;)
Answer: (c) syntax error on line 6.

Referring to the above, when m1(2) is invoked, m2() 7. Which of the following statements is correct?
and m1() returns which one of the following? throws an
ArithmeticException a) the 'try' block should be followed WBUT 2012, 2015]
a) 1 b) 2 by
a "catch' block
c) 3 d) 4 b) the 'try' block should be followed by a finally' block
Answer: (6) e) The system will exit c) the 'try' block should be followed by either a
d) the 'ca 'blo or a 'finally' block
'try' block should be followed by at least two
3. How can 'catch' blocks
you have a "try" block that
invokes methods that throw two Answer: (c)
exceptions? different
a) Catch one exception in a "catch" WBUT 2008] 8. Stack over run Is an
b) Setup nested "catch" blocks for block and the other in a "finally" block a) error
WBUT 2014, 2015]
c) Catch one exception in a "catch" each exceptioon b) exception c) virus d) worm
Answer: (b)
d) Use wait () between the calls to block and the other via the return value
e) Include a "catch" block for each process all exceptions before continuing
Answer: (e) exception Short Answer Type Questions
4. How can 1. How Throws and Throw
you ensure that the
memory allocated by an are different? Explain. WBUT 2011, 2016]
object is freed? OR,
a) By invoking the free WBUT 2009] Discuss the difference between 'throw' and 'throws' clause.
method on the WBUT 2013]
b) By calling
system.gc() method
object Answer:
c)By setting all reference to the The throw clause
d) Garbage collection object to new
JVM top free the cannot be forced. The values (say null) The catch block however does not restrict the normal flow of execution, which is outside

Answer: (d) memory used by an objectprogrammer cannot torGe the try-catch block. But it is a good.practice to stop fiurther execution ater an exception
as occurred. In such a situation the throw to stop execution of a
is
clause used explicitly
progranm flow alter a try block throws an exception. We use the throw statement in eatch
5. Which exception is thrown by the block, where the exception is captured. I he throw statement is used normally to throw
read() method of
a) Exception inputStream class0091 Checked exCeption like 1OExceptionn. sQL.ENCeption. \Whenever a checked exNception is
d) lOException b) FileNotFoundException [WBU hrown explicitly by a throw clause. we need to Luse the throWs clause also in the method
Answer: (d) e) None of these c) ReadException
rom wliere tie exeeption is thrown.

0OPM-90 O0PM-91
POPULAR PUBLICATIONS OBIECT ORIENTED PROGRAMMING
The throws clause
ve from the diagram, Throwable has two direct descendants:
can see
method signature, which throws a checked e v c o .
Error and EXception.
The throws clause is used as a
throw a checkea exception from a catch blois
to be remembered that whenever you ock, the
method must associate the throws clause. Errors

2. Why does the compiler generate Exception in thread "main" java.lang.


WBUTNo 2011]
s
dynamic inking failure or some other "hard" failure in the virtual macn
a

ccurs. the virtual machine throws an Error. Typical Java programs shou not
Such
Method Error: main. catch Errors. In addition, it's unlikely that typical Java programs will ever throw ETO
Answer: either.
The name of the exception suggests that the program tried to call a method that d
oesn't
exist. In this context, it sounds like the program does not have a main method, thouh Exceptions
would help if you posted the code that caused the error and the context in which hee cods
code
Most programs throw and catch objects that derive from the Exception class. Exceptions
was run. indicate that a problem occurred but that the problem is not a serious systemic problem.
user tried to runa .class Most programs you write will throw and catch Exceptions.
This might have happened ifthe file or a .jar file that has n0 main The Exception class has many descendants defined in the Java packages. hese
method in Java, the main method is the entry
-
to
point begin executing the program.
Normally the compiler is supposed to prevent this from happening so if this does happen descendants indicate various types of exceptions that can occur. For exampi
it's usually because the name of the method being called is getting determined at run llegalAccess Exception signals that a particular method could not be found.
time, rather than compile-time. andNegativeArraySizeException indicates that a program attempted to create an array
To fix this problem, a new programmer must either add the "main' method with a negative size.
that its main that's missing) or change the method call to the name
(assuming still One Exception subclass has special meaning in the Java language: RuntimeException.
exist.
of a method that does
Runtime Exceptions
the Java virtual
3. Discuss the Exception class hierarchy stating from the 'Throwable' The RuntimeException class represents exceptions that occur within
class. machine (during runtime). An example of a runtime exception NullPointerException,
is
WBUT 2013] an object through a null
Answer: which occurs when a method tries to access a member of
tries to dereference a
This diagram illustrates the class
hierarchy of the Throwable class and its most reference. A NullPointerException can occur anywhere a program
often outveighs the benefit
significant subclasses. reference to an object. The cost of checking for the exception
of catching it.
of
Object Because runtime exceptions ubiquitous and attempting to catch or specity all
are so

them all the time would be a fruitless exercise (and a fruitful source of unreadable and
to go uncaught and
unmaintainable code). the compiler allows runtime exceptions
Throwable unspecified. these
RuntimeException classes. We can catch
The Java packages define several
like other exceptions. Howe ver,
a method is not required to specify that it
exceptions just addition, you can create your own
In
EXception throws RuntimeExceptions. he Controversy contains a thorough
RuntimeExceptionsubclasses. Runtime ExCeptions--
Error runtime exceptions.
of when and how to
use
Oiscussion

Runtim eEXception
Long Answer Type Questions
with examples, user defined and system defined
1. What are exceptions? Explain, [WBUT 2005]
exceptions. OR,
can be created and thrown.
Explain how user defined exception objects
WBUT 2013]

OOPM-93
0OPM-92
POPULAR PUBLICATIONS
Answer: OBJECT ORIENTED PROGRAMMING
Exceptions in java are any abnormal, unexpected events or extraordinary co Answer
may occur at runtime. They could be file not found exception. unable to conditic Ons thar 1 Part:
exception and so on. On such conditions java throws an exception ohiotio In Java input is
taken from the
method or keyboard by passing command line
by using methods in
Exceptions are basically Java objects. No Project can never escape a java error. Java from the class from arguments to
the i
A user defined exception is exception class by API provider
provided or BufferedReader and
Streamtokenizer classes.Java 1/0 like
nputduca
provider which extends Exception defined in the classes of JAVA API.IU's eCation If command line
arugements are used then
with the unconventional action in your codes.JA VA use try-catch Ised interpreter. For
example java Test 1 23. This will passpass the arguments we
with java
construct to tal. 3 arguments to the main
In user defined exception class.you must rewrite method extends
its parent
The argumentsIpasSed will be accepted in the String metnod.
array that is parameterized in the
Exception. You can throw the exception out in try construct and deal with in catch class main method. he string array is then iterated and
converted to required data ype
Imports System operation. o
Public Class EmployeeListNotFoundException The other way of
accepting input from
the key board is to the input eventS Dy
Inherits Exception wrapping the system.in in a BufferedReader. The followingcapture
piece of code explains the
Public Sub New () same
End Sub
Public Sub New (message
BufferedReader br =
new BufferedReader (new
As String)
MyBase. New (message) InputstreamReader ( System.in));
int count 0;
End Sub double sum = 0;
Public Sub New (message As String, inner As StreamTokeni zer st new StreamTokenizer (br) ;
Exception)
MyBase.New (message, inner) if (st.nextToken () ==
st.TT_NUMBER)
End Su'
End Class count. = (int) st.nval; r e t u r n s the actual mumeric value
system defined exceptions are created by the java
compiler itself.
Example (a progranm that, tries to open a file named by the first
System.out.println():
br = new BufferedReader (new
for reading) command-line argument InputStreamReader (System. in) ) ;
public static void main (String [] st new StreamTokenizer (br)
args)
System.out.println ("Enter the
numbers: ")
for (int i = 0; i< count;)
Inputstreamistream;
File
inputFile; double num = 0;
try (
lf (st.nextToken ( ) == st.TT_NUMBER)
inputFile =
new
File(args [0])
istream = new
/ may throw
Input Stream (inputFile) ; num = st.nval;

catch FileNotFoundException i++


(FileNotFoundException ex) (
System.out.println("£ile "+args [0] +"
not found" ); else
"Please enter a valid Number") ;
ystem.out.println (
2. How can we i = i == 0 ? 0 i - - i
take input from a
does the try, catch block
do? What
keyboard? What is exception
handling What Continue;
throws are used to handle an
Write down the life Excepna72008]
WBUT 2007, 2008) Sum= sum + nun;
cycle of an
Applet with diagram.
WBUT 2007, 2008, 2009, 2010, 2014 is very important any programming. in during A program execution
Explain applet life OR, Exception Handling based on bad data, improper manipulation etc. AIl these
cycle with state transition diagram. WBUT 2011] may have abnormal behavior execution. The user has to be informed with this
flow of normal
Situations stop the

0OPM-95
0OPM-94
POPULAR PUBLICATIONS OBIECT ORIENTED PROGRAMMING
Lastly, a try block should alway be
In Java exceptions are broadlu
are broadly classified foll
abnormal flow with proper exception handling. compilation errors. by a catch or a finally block to avoid any
into two types:
. Checked Exception 2 nd Part:

Unchecked Exception An applet has the following life eycle,


sit:
init: Theinit () method is
called exactly once, when the applet is first
Checked Exceptions
of a program. Such
ormally used to initialize some parameters,
norn
loaaed 's
which needs only one time initialization
These types of exceptions are checked during compilation during the execution time of the
are presumed because their occurrence can be due to some other faulty process. T ceptions applet.
ypical start: The start () method is called at
In some cases it may be called least once, when the applet is started or
scenarios can be:
more than once. A restartcu
The executable class is not found in the classpath when we try to load a
class etart() method iS often used to start
any threads
using Class.forName. This is handiled by ClassNotFoundException the applet will need while it runs. Start 0
There can be hardware faults during file reading and printing which is handled hu stop: The stop () method is called at
least once, nit 0 destroy 0
the class IOException. when the browser window is stopped
There can be some network failures to connect to a remote database or it may ho loading in
which the åpplet is embedded. The (Stop 0
a wrong SQL statement. All these scenarios
applet's
start()
are presumed and will handled by method will be called if at some later point the browser returns to the
page containing the
the class SQLException. applet. In some cases the stop() method may be called multiple times in an applet's life
cycle. An applet should use the stop() method to pause any running threads.
Unchecked Exceptions destroy: The
destroy () method is called exactly once in an applet's life, just before the
These of
types exceptions occur during the execution of a
cannot be presumed because they may ocur due to erroneous program. Typical scenarios
program. Such exceptions browser unloads the applet. This method is generally used to perform clean up of
resources held by the applet.
can be that a method call is initiated on an object, which is null. The Java runtime system
signals it as a NullPointerException. Or it may be an incompatible assignment between 3. What is the base class of Error and Exception? WBUT 2008, 2016]
object references, which can result in ClassCastException. Differentiate between Error and Exception. WBUT 2008, 2012, 2015]
Answer:
Exception handling in Java is
done by
code which can throw an exception is kept in a
using
try, catch, throw, throws and finally. 1The
The base class of Error and Exception is java.lang.Throwable.
try block. If an exception is throw from a
try block then it is caught in the catch block. After catching the exception it has to An Error is a subclass of Throwable that indicates serious problems that a programmer
thrown back from the catch block so that the rest of the
be should not try to catch in the application. Most such errors are abnormal conditions like
program after the catch block java.lang.OutOfMemoryError. This is a critical error as this i_ given when a JVM crashes
does not execute. This is done by the throw method. When an exception is thrown from a
catch block the method should have a signature which indicates that an exception can be and no more memory could be made available by the garbage collector.
thrown. This is done by the throws. The code below An Exception is also a subclass of Throwable that indicates problems that a programmer
explains all of the Exceptlon
public String convertStringToInt (String 'str) throws
above
t will try to catch in the application. Most such errors appfication based like 1OException
try or ArithmeticException etc.

Can override that method


4. Give a method that does not declare any exception.
int we
Integer.parseInt (str);
x =

WBUT 2009]
str
String.value0f (x);
=

in a subclass to throw an exception?


return str; Answer: Yes.
The rule is,
catch (Number a super class throw a exception then it's subclass has to throw that exception or a
Format Exception nfx)
throw Subclass of the exception or
none
new
Exception( "Not a valid number" nfx) ,
write program to handle user defined
.What do you mean by exception? WBUT 2014]
A
finally block is used when exception.
block of code to be
irrespective of any exception caught or throw
vant

nally
executed. In such a scenario 0OPM-97
block. we put the block of cod

0OPM-96
POPULAR PUBLICATIONS Par OBIECT ORIENTED PROGRAMMING
evception called
Answer:
1" Part: ofa program
equals 3.
quaiot
class
to 14.
Equal ExXception
NotEqual Exc "NotEqualException" that is thrown
An exception is an event, which
occurs during the execution ogram, that disrupts oublic String msg; extends
the normal flow of the program's
instructions. blic Not Exceptior
ion

When an error occurs within a method,


the method creates an object and hand.
t
contains informationoff to
superEqualException
() ()
the runtime system. The object, called an exception object,
error, including its type and the
state of the program when the error occurred. C t the
called throwing an ercen an Dublic
exception object and handing it to the runtime system is
After a method throws an exception, the runtime system attempts to find somethin NotEqualException (String msg)
this.msg = msg;'
handle it. The set of possible "somethings" to handle the exception is the ordered list of
methods that had been called to get to the method where the error occurred. The
list of
methods is known as the call stack (see the next figure). publi class NotEqual
Method where error occured
Method cal
public staticExceptionDemo
void
(
main(String[)
Not EqualException ( args throws
Method without an exception float
handler Method call
f=Float.parseFl oat (args [ 0])
if (f!=3.14) (
throw new
Method with an exception NotEqual Exception ();
handler
Method call
maln

The call stack:


The runtime system searches the call stack for a method that contains a block of code that
can handle the exception. This block of code is called an exception handler. The search
begins with the method in which the error occurred and proceeds through the call stack
the reverse order in which the methods were called. When an appropriate handler is
found, the runtime system passes the exception to the handler. An exception handler is
considered appropriate if, the type of the exception object thrown matches the type that
can be handled by the handler.
The exception handler chosen is said to catch the exception. If the runtime system
exhaustively searches all the methods on the call stack without finding an appropriate
exception handler, as shown in the next figure, the runtime system (and, consequenty,
the program) terminates.
Throws exception Method where error occurred
Looking for
appropriate
Forwards exception Method without an exception handler
handler Looking for
appropriate
Catches some Method with an exception handler
other exception handler
main
Searching the call stack for the exception
Using exceptions to manage handler error
errors has some advantages over traalo OOPM-99
management techniques.
0OPM-98
POPULAR PUBLICATIONS
OBIECT ORIENTED PROGRAMMIN
JAVA INPUT/OUTPUT
THREADS
Choice Type Questions
Multiple Choice Type
Multiple Questions
WBUT 2008] 1
JAlhen we implement the Runnable interface, we must define the method
1. class Class1 (
a) start ( b) init () c) run () d) runnable () WBUT 2007]
static inti= 0; Answer: (C)
void main (String args[]) {
public static 2) {
for (intj = 1; j <args.length; j
+
2.
alhich one of the following statements is FALSE? WBUT 2008, 2009]
argsj] ); a) Java supports multi-threaded programming.
it= Integer.parselnt ( Threads in a
single program can have different priorities
cMultiple threads can manipulate files and get user input at the same time
System.outprintin(i); d Two threads can never act on the same object at the same time
e Threads are created and started with different methods.
the output of the
What parameters could be passed on the command-line so that Answer: (d)
above is "6"?
program c)6 3.Which one of the following is the equivalent of main () in a thread ?
a) 1 2344 b)651 Exception
throw an ArraylndexOutofBounds
d) None. The system will because an exception WBUT 2008, 2011]
must
an error message
e) None. The compiler will issue a) start () b) go () C) run () d) begin ()
be caught when invoking parselnt () e) The class constructor
Answer: (a) Answer: (c)

2. What type of the following stream is used to read binary data? WBUT 2012] 4. Which of the following statements is true? WBUT 2009]
b) InputStream Reader
a) InputStream a) The wait method defined in the thread class can be used to convert a

c) DatalnputStream d) none of these thread from running state to waiting state


b) The wait( ), notify( ) and notify all( method must be executed in
Answer: (a)
synchronized code
3. In System.out.printin(); out is wBUT 2014, 2015] c) the thread class is an abstract class
b) output stream object d) None of these.
a) a classs
c)method d) none of these Answer: (a) and (b)
Answer: (b) 5.The methods wait () and notify () are defined in WBUT 2011]
WBUT 2014, 2015] a) java.lang.string b) java.lang.runnable
4. Scanner class resides in
c)java.lang.object d) java.lang.thread
a) java.ioo b) java.applet c) java.util d) n o n e of these
Answer: (d)
Answer: (a)
to WBUT 2012, 2015]
0.
The wait( ) and notify() methods are used b)pertform
synchronization
LLong Answer Type Questions a) interthread communication
d) all of these
c) deadlock
1. Write short note on String Tokenizer Class. WBUT 2012] Answer: (b)
Answer: WBUT 2012, 2015]
class takes an input stream and parses it into "tokerns", allowin
the .Which one of the following is wrong
The Stream Tokenizer
tokens to be read one at a time. Runnable' is a predefined intertace to
a thread terminate its execution
ringTokenizer sTokenize o The sleep( ) method instructs thread has not yet died
=

while (Tokenize.hasMoreTokens()) {
new
StringTokenizer(s," "); ne isAlive( ) method tells whether a
level 10
MAX_PRIORITY represents the
Answer: (b)
0OPM-10
0OPM-100

You might also like