Thursday 6 April 2017

Java Solved Paper

NIELIT Java Sample Paper Solved
July, 2013
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 is a valid key word in Java?
A) Integer
B) unsigned
C) string
D) class

1.2 public interface
{
int i=10;//line1
}
Which piece of codes is equivalent to line 1?
A) public int i = 10;
B) static int i = 10
C) public static int i = 10;
D) public static final int i = 10
1.3 Which one is a valid declaration of a Boolean?
A) boolean b1 = 0;
B) boolean b2 = 'false';
C) boolean b3 = false;
D) None of the above
1.4 What will be the output of the following code segments?
int x = 0xf1;
x = byte(x >>3);
System.out.println(x);
A) -1
B) -2
C) 1
D) 2

1.5 Exception and Error are immediate subclasses of a class called
A) Object
B) Throwable
C) AWT
D) Panel
1.6 Dynamic method dispatch is an example of
A) template
B) Run-time polymorphism
C) Compile-time polymorphism
D) specialization
1.7 In a package if a class is declared without any keyword then
A) It can-not be inherited.
B) It can be accessed in another package.
C) It can-not be accessed in another package.
D) It is private by default
1.8 Protected member of a class in JAVA
A) Can be inherited by derived class but cannot be accessed directly through an object
B) Cannot be inherited by derived class and can be accessed directly through an object
C) Can be inherited by derived class and can be accessed directly through an object
D) Cannot be inherited by derived class and cannot be accessed directly through an object
1.9 If a method is declared as final in a class then
A) It can-not be accesses outside the class
B) It can be redefined in a subclass
C) It can-not be inherited in a subclass
D) None of the above
1.10 Class diagram at conceptual level should include
A) attributes only
B) operations only
C) Both attributes and operations
D) None of the above

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 Swing relies on operating system for its functionality.
2.2 Constructor has no return type.
2.3 In object oriented programming data can not be directly accessed out-side the class without
object.
2.4 Applets do not need a main method.
2.5 The name of a java program file must match the name of the class.
2.6 Declaration can appear anywhere in the body of java method.
2.7 Java technology is both a programming language and a platform.
2.8 Java programming is not statically-typed, means all variables should not first be declared
before they can be used.
2.9 In a method or a constructor, "this" is a reference to the current object.
2.10 Default case is always required in switch.

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
Compares characters inside String Object
A.
Panel
3.2
System. in is an object of type
B.
PrintStream
3.3
A class declared as final cannot be
C.
Instantiated
3.4
Super class of all events
D.
InputStream
3.5
The immediate super class of applet class is
E.
Runtime
3.6
Method overloading is an example of polymorphism caused at
F.
equals ()
3.7
Code reusability is achieved through
G.
Inherited
3.8
Exception is an error caused at
H.
== operator
3.9
Abstract classes cannot be
I.
Method overriding
3.10
Base class constructor can be invoked using
J.
EventObject


K.
Compile time


L.
Inheritance


M.
super

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.
paint()
B.
isAlive() and join()
C.
finally
D.
static
E.
Error
F.
Wait() and notify()
G.
Component
H.
java.lang
I.
Container
J.
Panel
K.
public
L.
private
M.
toString()





4.1 ________ data member is shared among all instances of that class.
4.2 Immediate super class of Panel class is ________.
4.3 Constructors are defined in ________ section of a class.
4.4 Functions used for string representation of object is ________.
4.5 ________ are used to achieve inter-thread communication.
4.6 Java automatically import ________ package.
4.7 ________ contains the exceptions which are not supposed to handle by user program.
4.8 try block without catch must have ________ block.
4.9 Container is a subclass of ________ class.
4.10 When an applet output must be redrawn a ________ method is invoked.

PART TWO
(Answer any FOUR questions)

5.
a) Why Java is called platform independent?
b) “Abstraction and encapsulation are complementary to each other”. Justify.
c) Can an abstract method be declared final? Explain your answer.
(5+5+5)
6.
a) Write a program in Java to sort a list of integers given at command line.
b) What is an abstract class in Java? Differentiate between interfaces and abstract classes.
c) Modify the following method so that it will compile:
public static void Fin(File file) {
RandomAccessFile input = null;
String line = null;
try {
input = new RandomAccessFile(file, "r");
while ((line = input.readLine()) != null) {
System.out.println(line);
}
return;
} finally {
if (input != null) {
input.close();
}
(5+6+4)
7.
a) What is the difference between throw and throws? Explain with example.
b) Can we declare a constructor private? Explain.
c) Write the output of the following code segment:
int i= 0xFFE;
int b=1;
i= i<<b+2;
System.out.println(“i=”+i);
(8+4+3)
8.
a) What is finalize() method in Java? How is it used? Explain.
b) Differentiate between overloading and overriding with the help of suitable example.
c) Given the program below, what will be the values of sum1 and sum2?
public class MyArray
{
private int [ ] A={3, 4, 5};
public MyArray( )
{
}
public int value( )
{
return(A[0]);
A10.1-R4 Page 6 of 6 July, 2013
}
public int value(int k)
{
return(A[k]);
}
public static void main (String[ ] args)
{
MyArray [ ] arr= new MyArray[10];
int sum1 = 0, sum2 = 0;
for(int i=0; i<10; i++)
{
arr[i]=new MyArray( );
sum1 = sum1 + arr[i].value( );
for(int j=0; j<3; j++)
sum2 = sum2 + arr[i].value(j);
}
System.out.println("sum1: "+ sum1 + " sum2: " + sum2);
}
}
(5+6+4)
9.
a) What is an applet in java? What are basic methods defined in an Applet class? Explain
briefly.
b) What is the difference between the windows generated by Panel class and Frame class?
Explain.
c) What is the difference between sequence diagram and communication (aka collaboration)
diagram? Can a sequence diagram be replaced by communication diagram?
(6+4+5)

No comments:

Post a Comment