Thursday, 6 April 2017

Java Solved Paper

NIELIT A LEVEL Java Solve Paper
July, 2014
A10.1-R4: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING THROUGH JAVA

PART ONE
(Answer all the questions)

1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in the “OMR” answer sheet supplied with the question paper, following instructions therein. (1x10)

1.1 Which of the following is possible in a class if class is declared as an abstract?
A) Instance block
B) Static block
C) Final method
D) All of the above

1.2 How do objects communicate during execution?
A) They communicate by modifying each other’s fields.
B) They communicate by modifying the static variables of each other’s classes.
C) They communicate by calling each other’s instance methods.
D) They communicate by calling static methods of each other’s classes.
1.3 What is the default encoding for output stream writer?
A) UTF-8
B) UNICODE
C) 8859_1
D) The default is System-dependent
1.4 Which of these array declaration statements are not legal?
A) int[] i[] = { { 1, 2 }, { 1 }, {}, { 1, 2, 3 } };
B) int i[] = new int[2] {1, 2};
C) int i[][] = new int[][] { {1, 2, 3}, {4, 5, 6} };
D) int i[][] = { { 1, 2 }, new int[ 2 ] };
1.5 Given the following code within a method, which statement is true?
int a, b;
b = 5;
A) Local variable a is not declared.
B) Local variable b is not declared.
C) Local variable a is declared but not initialized.
D) Local variable b is initialized but not declared.
A10.1-R4 Page 2 of 5 July, 2014
1.6 What will be the result of compiling the following program?
public class MyClass {
long var;
public void MyClass(long param) { var = param; } // (1)
public static void main(String[] args) {
MyClass a, b;
a = new MyClass(); // (2)
b = new MyClass(5); // (3)
}
}
A) A compilation error will occur at (1), since constructors cannot specify a return value.
B) A compilation error will occur at (2), since the class does not have a default constructor.
C) A compilation error will occur at (3), since the class does not have a constructor that takes one
argument of type int.
D) The program will compile without errors.
1.7 Which one of the following class declarations is a valid declaration of a class that cannot be
extended?
A) class Link { }
B) abstract class Link { }
C) static class Link { }
D) final class Link { }
1.8 What is the result of running the following program?
public class OperandOrder {
public static void main(String[] args) {
int i = 0;
int[] a = {3,6};
a[i] = i = 9;
System.out.println(i + " " + a[0] + " " + a[1]);
}
}
A) When run, the program throws an exception of type ArrayIndexOutOfBoundsException.
B) When run, the program will print "9 9 6".
C) When run, the program will print "9 0 6".
D) When run, the program will print "9 0 6".
1.9 We typically identify the attributes of the classes in our system by analyzing the ________ in the
requirements document.
A) nouns and noun phrases
B) descriptive words and phrases
C) verbs and verb phrases
D) All of the above.
1.10 The UML uses an arrow with a ________ to indicate a generalization relationship.
A) solid filled arrowhead
B) triangular hollow arrowhead
C) diamond-shaped hollow arrowhead
D) stick arrowhead

2. Each statement below is either TRUE or FALSE. Choose the most appropriate one and ENTER in the “OMR” answer sheet supplied with the question paper, following instructions therein. (1x10)

2.1 A JPanel cannot be added to another JPanel.
2.2 If an attribute of a class is marked with a minus sign (-) in a class diagram, the attribute is not
directly accessible outside the class.
2.3 An object’s state is indicated by the values of all its attributes at a given time.
2.4 All methods declared in an interface are implicitly public abstract final methods and all fields are
implicitly public, static and final.
2.5 Constructors cannot be inherited or overridden.
2.6 Protected members of the superclass are not inherited by the subclass and can only be
indirectly accessed.
2.7 It is not possible to create arrays of any type with length zero.
2.8 A constructor cannot be declared as final.
2.9 static, unsigned, and long are keywords in the Java language.
2.10 Objects in Java cannot contain other objects; they can only contain references to other objects.

3. Match words and phrases in column X with the closest related meaning/word(s)/phrase(s) in column Y. Enter your selection in the “OMR” answer sheet supplied with the question paper, following instructions therein. (1x10)

X
Y
3.1
Class scope concerns accessing members (including inherited ones) from code within
A.
overridden
3.2
Casting can be applied to primitive values as well as
B.
constructo .
3.3
A final method cannot be
C.
a termination test
3.4
super() can only occur as the first statement in a
D.
down casting
3.5
Casting a reference stored in a superclass variable to a subclass type is called
E.
a class
3.6
Iteration and recursion each involve
F.
the String class
3.7
An I/O-performance-enhancement technique in stream is known as
G.
references
3.8
Method compareTo is declared in the Comparable interface and implemented in
H.
buffering
3.9
A dialog capable of displaying a message to the user is displayed with method of class
I.
overloading
3.10
the UML specifies that hollow diamonds be attached to the ends of association lines to indicate
J.
JOptionPane


K.
JButton


L.
aggregation


M.
Composition

4. Each statement below has a blank space to fit one of the word(s) or phrase(s) in the list below. Enter your choice in the “OMR” answer sheet supplied with the question paper, following instructions therein. (1x10)

A.
import
B.
package
C.
instance method
D.
Parentheses, ( ),
E.
Label
F.
JCheckBox
G.
override
H.
switch
I.
java
J.
checked exceptions
K.
abstract
L.
activity diagram
M.
overloading





4.1 At most one ________ declaration can appear in a source file, and it must be the first statement
in the source file.
4.2 A JAR file can only be specified for use with the ________ command, in order to run a program.
4.3 A class can be declared with the keyword ________ to indicate that it cannot be instantiated.
4.4 ________ can be used to override precedence and associativity.
4.5 If no case label is equal to the value of the ________ expression, the statement associated with
the default label is executed.
4.6 The compiler enforces that the ________ thrown by a method are limited to those specified in
its throws clause.
4.7 A subclass can ________ a method defined in its superclass by providing a new
implementation.
4.8 A(n) ________ in a subclass cannot override a static method in the superclass.
4.9 A(n) ________ models the actions the object performs and specifies the order in which it
performs them.
4.10 When the user clicks a(n) ________, an ItemEvent occurs. This event can be handled by an
ItemListener object, which must implement method itemStateChanged.

PART TWO
(Answer any FOUR questions)

5.
a) A listener is called when the user does something to the user interface that causes an event.
List and explain the MouseListener and MouseMotionListener interface methods.
b) A GUI is a graphical (rather than purely textual) user interface to a computer. Explain
Lightweight vs. Heavyweight GUI Components. Write the difference between Swing and AWT.
c) At any time, a thread is said to be in one of several thread states. Draw UML state diagram of
Thread life cycle.
(5+5+5)
6.
a) Every expression written in the Java programming language has a type that can be deduced
from the structure of the expression and the types of the literals, variables. Write the conditions
to be fulfilled for implicit narrowing primitive conversions on assignment.
b) What is inheritance? List the benefits of inheritance? Why java doesn’t support multiple
inheritances?
c) Activity diagrams are graphical representations of workflows of stepwise activities and actions
with support for choice, iteration and concurrency. Draw the Activity Diagram for a switch
Statement.
(3+7+5)
7.
a) What is interface? How does interface differ from abstract class?
b) Various methods correspond to various aspects of an applet’s life cycle. List and explain the
Applet life cycle methods.
c) Write a Java program that demonstrates String methods equals, equalsIgnoreCase, compareTo
and regionMatches and using the equality operator == to compare String objects.
(5+5+5)
8.
a) Differentiate following ResultSet constants.
1. TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE
2. CONCUR_READ_ONLY and CONCUR_UPDATABLE
b) A class diagram in the Unified Modeling Language (UML) is a type of static structure diagram
that describes the structure of a system. Draw the Class diagram for the ATM system model
including class Deposit.
c) Write a Java program to do addition of given two numbers without using addition (+) operator.
(Hint: Use bitwise operator)
(4+5+6)
9. Write a short note on any three of the following:
a) The RuntimeException Class
b) Data I/O Streams
c) Short circuit operators
d) Aggregation and Composition
(3x5)