OOPJ Short QuestionBank 2016
OOPJ Short QuestionBank 2016
Sr No QUESTIONS
UNIT-1 BASICS OF JAVA:
stored in .class file which is created after compiling the source code.
Data types, Operator Control Statements – If , else, nested if, if-else ladders, Switch, while,
do-while, for, for-each, break, continue.
1 Is delete,next,main,exit or null keyword in java? 1
Ans: NO
2 List primitive Java types? 1
Ans: The eight primitive types are byte, char, short, int, long, float, double, and boolean.
3 Which of these can not be used for a variable name in Java? 1
a) identifier b) keyword c) identifier & keyword d) None of the mentioned
Answer: b) keyword
4 What is the output of this program? 1
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
a) 25 b) 24 c) 32 d) 33
Ans:c)32
TOPIC:1 (Array)
Single and Multidimensional Array
1 Which will legally declare, construct, and initialize an array? 1
A. int [] myList = {"1", "2", "3"}; B. int [] myList = (5, 8, 2);
C. int myList [] [] = {4,9,7,0}; D. int myList [] = {4, 3, 7};
Answer: D int myList [] = {4, 3, 7};
2 Which of these operators is used to allocate memory to array variable in Java? 1
a) malloc b) alloc c) new d) new malloc
Answer: c) new
3 Which of these is an incorrect array declaration? 1
a) int arr[] = new int[5] b) int [] arr = new int[5]
c) int arr[] arr = new int[5] d) int arr[] = int [5] new
Answer:d) int arr[] = int [5] new
4 Which of these is necessary to specify at time of array initialization? 1
a) Row b) Column c) Both Row and Column d) None of the mentioned
Answer: a) Row
5 What are ragged arrays in java and how are they implemented? 1/2/3
Ans: Ragged arrays : an array with rows of nonuniform length is known as a ragged array.
Syntaxt:
int[][] raggedArray = new int[n][];
for (int i=0; i<raggedArray.length; i++) {
raggedArray[i] = new int[i+1];
}
is specified.
TOPIC:3 (Interface)
Creation and Implementation of an interface, Interface reference, instanceof operator,
Interface inheritance, Dynamic method dispatch ,Understanding of Java Object Class,
Comparison between Abstract Class and interface, Understanding of System.out.println –
statement.
1 What is interface? 1
Ans: Interface is a blueprint of a class that have static constants and abstract methods. It
can be used to achieve fully abstraction and multiple inheritance.
2 Can an Interface extend another Interface? 1
Yes an Interface can inherit another Interface, for that matter an Interface cannot extends
more than one Interface.
3 Can you declare an interface method static? 1
Ans: No, because methods of an interface is abstract by default, and static and abstract
keywords can't be used together.
4 Can an Interface be final? 1
Ans: No, because its implementation is provided by another class.
5 What is difference between abstract class and interface? 1
Object Oriented Programming using JAVA (2150704) 2016 Page 6
L.J. Institute of Engineering & Technology Semester: V (2016)
UNIT-5 PACKAGES
Use of Package, CLASSPATH, Import statement, Static import, Access control
1 What is package? 1
Ans: A package is a group of similar type of classes interfaces and sub-packages. It
provides access protection and removes naming collision.
2 Do I need to import java.lang package any time? Why ? 1
Ans: No. It is by default loaded internally by the JVM.
3 What is static import ? 1
Ans: By static import, we can access the static members of a class directly, there is no to
qualify it with the class name.
4 What is difference between Path and Classpath? 1
Ans: Path and Classpath are operating system level environment variales. Path is defines
where the system can find the executables(.exe) files and classpath is used to specify the
location of .class files.
5 Which access specifiers can be used for a class so that it’s members can be accessed by a 1
different class in the different package?
A) Private B) Public C) Protected D) None of the above
ANSWER: B) Public
6 Which provides accessibility to classes and interface? 1
A) import B) Static import C) Both A & B D) None of the above
ANSWER: A) import
Ans: It is not necessary that each try block must be followed by a catch block. It should be
followed by either a catch block OR a finally block. And whatever exceptions are likely to
be thrown should be declared in the throws clause of the method.
2 What is Exception Handling? 1
Ans: Exception Handling is a mechanism to handle runtime errors.It is mainly used to
handle checked exceptions.
3 What is difference between Checked Exception and Unchecked Exception? 1
1)Checked Exception:
The classes that extend Throwable class except RuntimeException and Error are known as
checked exceptions e.g.IOException,SQLException etc. Checked exceptions are checked
at compile-time.
2)Unchecked Exception:
The classes that extend RuntimeException are known as unchecked exceptions e.g.
ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at
compile-time.
4 Can finally block be used without catch? 1
Ans: Yes, by try block. finally must be followed by either try or catch.
5 What is finally block? 1
Ans: finally block is a block that is always executed.
6 When throws keyword is used? 1
Ans: If a method does not handle a checked exception, the method must declare it using
the throwskeyword. The throws keyword appears at the end of a method's signature.
7 When throw keyword is used? 1
Ans: An exception can be thrown, either a newly instantiated one or an exception that you
just caught, by using throw keyword.
8 What is the difference between error and an exception? 1
Ans:An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory
error. Exceptions are conditions that occur because of bad input etc. e.g.
FileNotFoundException will be thrown if the specified file does not exist.
9 Exception Handling is a mechanism to handle runtime errors? 1
A) True B) False
ANSWER: A) True
10 These five keywords are used in try, catch, finally, throw, and throws? 1
A) Exception Handling B) String Handling C) Event Handling
D) None of the above
ANSWER: A) Exception Handling
11 These exceptions are seen in 1
NullPointerException, ArrayIndexOutOfBoundsException,
ArithmeticException, NumberFormatException ?
12 Which block contains a block of program statements within which an exception might 1
occur?
1 What is multithreading? 1
Object Oriented Programming using JAVA (2150704) 2016 Page 9
L.J. Institute of Engineering & Technology Semester: V (2016)
UNIT-8 IO PROGRAMMING:
LinkedList is better to
3) ArrayList is better to store and fetch data.
manipulate data.
Iterator traverses the elements in forward direction only whereas ListIterator traverses the
elements in forward and backward direction.
3 Define Dependency: 1
Dependency is the relationship between two things in which a change in one thing may
affect the other thing, but not necessarily the reverse. Graphically, it can be represented as
a dashed directed line, directed to the thing being depended on.
4 Single inheritance, Multiple inheritance, and Aggregation comes under _______ 1
a) Modularity b) Typing c) Hierarchy d) None of the mentioned
Answer: c
5 When two or more classes serve as base class for a derived class, the situation is known as 1
__________.
a) multiple inheritance b)polymorphism
c) encapsulation d)hierarchical inheritance
Answer: (a)
Package is the only one grouping thing available for gathering structural and behavioral
things.
instances.
C. A class that has direct instances, but whose descendants may not have direct
instances.
D. A class that has no direct instances, but whose descendants may not have direct
instances
Answer: Option B