0% found this document useful (0 votes)
19 views

Oops

This document contains 35 multiple choice questions about Java programming concepts. Some of the key concepts covered include variables and keywords in Java, classes and objects, inheritance, polymorphism, exceptions, threads, streams and collections. The questions test understanding of fundamental Java topics as well as newer features introduced in Java 8 such as lambda expressions and streams.

Uploaded by

Samiksha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Oops

This document contains 35 multiple choice questions about Java programming concepts. Some of the key concepts covered include variables and keywords in Java, classes and objects, inheritance, polymorphism, exceptions, threads, streams and collections. The questions test understanding of fundamental Java topics as well as newer features introduced in Java 8 such as lambda expressions and streams.

Uploaded by

Samiksha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

=====================================================================

############## OOPS ##############


=====================================================================

1. Which of these can not be used for a variable name in Java?


Answers
1. identifier
**2. keyword
3. identifier & keyword
4. none of the mentioned

=====================================================================

2. Which of the following best defines a class?


Answers
1. Parent of an object
2. Instance of an object
**3. Blueprint of an object
4. Scope of an object

=====================================================================

3. Which component is used to compile, debug and execute the java programs?
Answers
1. JRE
2. JIT
**3. JDK
4. JVM

=====================================================================

4. predict the output of following java program?

class Test
{
int i;
}
class Main{
public static void main(String[] args)
{ Test t;
System.out.println(t.i);
}
}
Answers
1. 0
2. garbage value
**3. compiler error
4. runtime error
=====================================================================

5. When Overloading does not occur?

Answers
1. More than one method with same name but different number or type of parameters
2. More than one method with same name but different number of parameter
3. More than one method with same name, same number of parameters but different
type of parameters
**4. More than one method with same name, same number of parameters and same type
of parameters but return type is different

=====================================================================

6. Which concept of Java is achieved by combining methods and attribute into a


class?

Answers
**1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction

=====================================================================

7. What will be the output of the following program?


class Base {
final public void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public void show() {
System.out.println("Derived::show() called");
}
}

class Main {
public static void main(String[] args) {
Base b = new Derived();
b.show();
}
}

Answers
1. Base::show() called
2. Derived::show() called
**3. Compiler error
4. Runtime error
=====================================================================

8. Which of this keyword can be used in a subclass to call the constructor of


superclass?

Answers
**1. super
2. this
3. extent
4. extends

=====================================================================

9. Which of these class is superclass of every class in Java?

Answers
1. String class
**2. Object class
3. Abstract class
4. ArrayList class

=====================================================================

10. What is upcasting?

Answers
**1. Casting subtype to supertype
2. Casting super type to subtype
3. Casting subtype to super type and vice versa
4. Casting anytype to any other type

=====================================================================

11. What will be the output of the following Java code?


class conversion
{
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}

Answers
1. 38 43
**2. 39 44
3. 295 300
4. 295.04 300

=====================================================================

12. Which of these is a wrapper for data type int?

Answers
**1. Integer
2. Long
3. Byte
4. Double

=====================================================================

13. Which method can be defined only once in a program?

Answers
**1. main method
2. finalize method
3. static method
4. private method

=====================================================================

14. Which of these class represents mutable character sequence?

Answers
1. String
2. StringBuffer
3. StringBuilder
**4. Both StringBuffer and StringBuilder

=====================================================================

15. Which of these method of class String is used to compare two String objects for
their equality?

Answers
**1. equals()
2. Equals()
3. isequal()
4. Isequal()

=====================================================================

16. Which of these process occur automatically by the java runtime system?

Answers
**1. Serialization
2. Garbage collection
3. File Filtering
4. All of the mentioned

=====================================================================

17. Which of the following class we can used to read the data in the form of
character from text file?

Answers
1. FileWriter
**2. FileReader
3. FileInputStream
4. FileOutputStream

=====================================================================

18. What will be the output of the following Java code?


enum Season
{
WINTER, SPRING, SUMMER, FALL
};
System.out.println(Season.WINTER.ordinal());

Answers
**1. 0
2. 1
3. 2
4. 3

=====================================================================

19. Which of the following are disadvantages of generics?

Answers
1. Cannot Instantiate Generic Types with Primitive Types
2. Cannot Create Instances of Type Parameters
3. Cannot Overload a Method Where the Formal Parameter Types of Each Overload Erase
to the Same Raw Type
**4. All of the above

=====================================================================

20. What is the return type of lambda expression?

Answers
1. String
2. Object
3. void
**4. Function
=====================================================================

21. While iteration is on and some other thread tries to modify the collection then
iterator throws following exception?

Answers
**1. ConcurrentModificationException
2. CollectionModificationException
3. RandomAccessException
4. None of the above

=====================================================================

22. Which of these methods can be used to obtain a array from an ArrayList object?

Answers
1. Array()
2. convertArray()
**3. toArray()
4. covertoArray()

=====================================================================

23. The accuracy and efficiency of a HashMap can be guaranteed with

Answers
1. override equals method
2. override hashCode method
**3. Both of the above
4. None of the above

=====================================================================

24. How to get UTC time?

Answers
1. Time.getUTC();
2. Date.getUTC();
**3. Instant.now();
4. TimeZone.getUTC();

=====================================================================

25. What will be the output of following programs?


class Base extends Exception {}
class Derived extends Base {}

public class Main {


public static void main(String args[]) {
// some other stuff
try {
// Some monitored code
throw new Derived();
}
catch(Base b) {
System.out.println("Caught base class exception");
}
catch(Derived d) {
System.out.println("Caught derived class exception");
}
}
}

Answers
1. Caught base class exception
2. Caught derived class exception
**3. Compiler Error because base class exception is caught before derived class
4. Compiler Error because derived is not throwable

=====================================================================

26. What is invalid about java.lang.Error in java?

Answers
1. Errors are abnormal conditions in application
2. Error indicates some serious problems that our application should not try to
catch
**3. Error is unchecked Exception
4. Error is a subclass of Throwable

=====================================================================

27. Which statement is true?

Answers
**1. catch(X x) can catch subclasses of X where X is a subclass of Exception
2. Any statement that can throw an Exception must be enclosed in a try block
3. The Error class is a RuntimeException
4. Any statement that can throw an Error must be enclosed in a try block

=====================================================================

28. Which of these is an interface for control over serialization and


deserialization?

Answers
1. Serializable
**2. Externalizable
3. FileFilter
4. ObjectInput

=====================================================================

29. Which of these is valid about threads in java?

Answers
1. Thread consumes cpu in best possible manner
2. Threads enables multi-processing
3. Threads can execute any part of process. And same part of process can be
executed by multiple Threads.
**4. All

=====================================================================

30. How can we create Thread?

Answers
1. By Extending Thread class
2. Implementing Runnable interface
3. By using Executor framework - which can internally form threads
**4. All of the above

=====================================================================

31. The synchronized keyword is applicable for whom?

Answers
1. Variables and Methods
2. Methods and Classes
3. Variables and Classes
**4. Methods and Blocks

=====================================================================

32. What are green threads in java?

Answers
1. Green threads are user-level threads
2. Green threads are high level threads
3. Green threads are OS level threads
**4. None

=====================================================================

33. What are the two types of Streams proposed by Java 8?

Answers
1. Random and synchronized
2. Parallel and random
3. Sequential and random
**4. Sequential and parallel

=====================================================================

34. Which of these variables is a static variable defined in Collections?

Answers
1. EMPTY_LIST
2. EMPTY_SET
3. EMPTY_MAP
**4. All the answers are true

=====================================================================

35. When does Exceptions in Java arises in code sequence?

Answers
**1. Run Time
2. Can Occur Any Time
3. Compilation Time
4. None of the mentioned

=====================================================================

36. What is -Xms and -Xmx while starting jvm?

Answers
**1. Initial memory; Maximum memory
2. Initial memory
3. Maximum memory
4. Maximum; Initial memory

=====================================================================

37. What allows the programmer to destroy an object x?

Answers
1. x.delete()
2. x.finalize()
3. Runtime.getRuntime().gc()
**4. Only the garbage collection system can destroy an object

=====================================================================

38. Which of these class relies upon its subclasses for complete implementation of
its methods?

Answers
1. Object class
**2. abstract class
3. ArrayList class
4. None of the mentioned

=====================================================================

39. Which of the following is an incorrect statement about Interface?

Answers
1. Interfaces specifies what class must do but not how it does
2. Interfaces are specified public if they are to be accessed by any code in the
program
3. All variables in interface are implicitly final and static
**4. All variables are abstract and methods are static if interface is defined
public

=====================================================================

40. What happens when we access the same variable defined in two interfaces
implemented by the same class?

Answers
1. Compilation failure
2. Runtime Exception
3. The JVM is not able to identify the correct variable
**4. The interfaceName.variableName needs to be defined

=====================================================================
*********************End******************
=====================================================================

You might also like