Java Question Paper 1
Java Question Paper 1
Total Marks: 75
Note :
• This answer key is an outline for the distribution of marks and brief concept of
the answer. The actual explanation can be taken from any prescribed text book.
• For Questions like 2e, 3d, 3f , These statements have to be explained in two
aspects. One is the syntax and the other one is their functionality and concept.
The aim is to test whether the student can interpret random and short code
snippets.
Ans) The given code reflects the concept of dynamic dispatch of method in java.
Here , the reference of base class Shape (gen) is assigned with either the object
of Rect ,(r) or the object of Circ (c) depending on the user’s input ( that means , it is
at run time) so , the behavior of the statement 5) gen.showdata() is decided at run
time. Hence it is dynamic dispatch of the method. (4m)
It can also be said that concepts of Wrapper class methods and commandline
arguments are represented because of the code line (3) (2m)
How do you create your own package and import it in a java program? Explain the
procedure step-wise using a suitable example.
Ans) The procedure should be explained step-wise giving any example code.
e.
Explain the below given code fragments :
(i) interface values extends demoval { … }
Ans) This code is the definition of an interface in java. Here defined
interface is ‘values’ which is extended from another interface ‘demoval’.
Here ‘interface’ and ‘extends’ are keywords. (2m)
(ii) class sample extends dsamp implements dval { .. }
Ans) In the above java code , ‘sample’ and ‘dsamp’ are class names and
‘dval’ is an interface. (1m)
Hence we can explain it as below :
This is the definition of a class ‘sample’ which is extended from another
f. class dsamp and implements an interface ‘dval’ (2m)
&&&