You are on page 1of 9

Core Java

1. --------------is a process of hiding the implementation details and showing


only functionality to the user
a) Encapsulation
b) Polymorphism
c) Abstraction
d) Inheritance

2. A method within a class is only accessible by classes that are defined


within the same package and the subclass of
another package. Which one of the following is used to enforce such
restriction?
a) Declare the method with the keyword public
b) Declare the method with the keyword private
c) Do not declare the method with any accessibility modifiers
d) Declare the method with the keyword protected

3. toString method is present in


a) Object class
b) String class
c) c)System class
d) d)Math class

4. Converting primitives to objects is called as


a) a)Serialization
b) auto boxing
c) unboxing
d) d)Sorting

5.Which of these class is not a member class of java.io package?


a) String
b) BufferedReader
c) FileReader
d) FileInputStream

6.Which of these is method for testing whether the specified element is a


file or a directory?
a) IsFile()
b) isFile()
c) Isfile()
d) isfile()

7. Which of these is correct way of inheriting class A by class B?


a) class B + class A
b) class B inherits class A
c) class B extends class A
d) class B extends A

8. non static variables are defined in


a) a)classes
b) Functions
c) both a and b
d) none of the above

9. what will be the output


class A
{
public static void main(String args[])
{
TreeSet t = new TreeSet();
t.add("3");
t.add("9");
t.add("1");
t.add("4");
t.add("8");
System.out.println(t);
}
}
a) [3, 9, 1, 4, 8]
b) [1, 3, 4, 8, 9]
c) [9, 8, 4, 3, 1]
d) Compilation error

10. Which of this interface must contain a unique element?


a) List
b) Set
c) Array
d) Collection

11. What is invalid about serialization in java?


a) Serialized object can be persisted into database.
b) Serialized object can't be persisted into file.
c) Serialization is process of converting object into byte stream
d) Serialized object can be transferred over network.

12. Which statement is true regarding an object?


a) An object is what classes instantiated are from
b) An object is an instance of a class
c) An object is a reference to an attribute
d) An object is a variable

13. A package in Java is a collection of:


a) Classes
b) Interfaces
c) Editing tools
d) Classes and interfaces.

14.If you are inserting any value in the wrong index as shown below,
1. int a[]=new int[5];
2. a[10]=50;
a) NullPointerException
b) ArrayIndexOutOfBoundsException
c) ArithmeticException
d) NumberFormatException

15. Which is a superclass of all exception classes?


a) Throwable
b) Exception
c) RuntimeException
d) IOException

16. What will be output


class A {
int i;
void display() {
System.out.println(i);
}
}
class B extends A {
int j;
void display() {
System.out.println(j);
}
}
class inheritance_demo {
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 0
b) 2
c) 1
d) Compilation Error

17. Which of these field declarations are legal within the body of an
interface?
a) aprivate final static int answer = 42
b) public static int answer=42
c) final static answer =42
d) dint answer

18. Which of the following is not a marker interface?


a) Serializable
b) Cloneable
c) Remote
d) Reader

19.What is the advantage of Reflection?


a) Examine a class’s field at compile time
b) Construct an object for a class at runtime
c) Examine a class’s field and method at runtime
d) Examine an object’s class at compile time
20.How private method can be called using reflection?
a) getDeclaredFields
b) getDeclaredMethods
c) getMethods
d) getFields

21.The concept of multiple inheritances is implemented in Java by:


I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.
a) Only (II)
b) (I) and (II)
c) (II) and (III)
d) Only (I)

22. What is the process of defining a method in a subclass having same


name & type signature as a method in its
superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned

23 What will be output


class A {
public static void main(String args[]) {
try {
System.out.print("Hello" + " " + 1 / 0);
}
catch(Exception e)
{
System.out.print("catch ");
}
finally {
System.out.print("World");
}
}
}
a) Hello World
b) catch Hello
c) catch World
d) Compilation Error

24. Which of these is not a correct statement?


a) Every class containing abstract method must be declared abstract
b) Abstract class can contain fields and implemented methods.
c) Abstract class can be initiated by new operator
d) Abstract class can be inherited

25.Which of these access specifiers can be used for an interface?


a) Public
b) Protected
c) Private
d) All of the mentioned

26. What will be output


class A
{ static int i;
public void m1()
{
System.out.println("value of i is" + i);
}
public static void main(String[] args) {
A obj = new A();
A obj1 = new A();
obj.i = 3;
obj1. i =4;
System.out.println(obj1.i + " " + obj.i);
}
}
a) 4 3
b) 3 4
c) Compilation error
d) 4 4

27. Which is the new method introduced in java 8 to iterate over a


collection?
a) for (String i : StringList)
b) foreach (String i : StringList)
c) StringList.forEach()
d) List.for()

28. Which of these statements is incorrect?


a) By multithreading CPU idle time is minimized, and we can take
maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum
use of it
c) thread priority can be changed.
d) A thread can exist only in two states, running and blocked

29.Which of these method of Thread class is used to find out the priority
given to a thread?
a) get()
b) ThreadPriority()
c) getPriority()
d) getThreadPriority()

30. FileWriter fw =new FileWriter("a.xyz");


we are using this code for
a) Binary based IO
b) Text based IO
c) Both a and b
d) Object based IO.

31.Which of these exception is thrown by close() and read() methods?


a) IOException
b) FileException
c) FileNotFoundException
d) FileInputOutputException

32. Which of these standard collection classes implements a dynamic


array?
a) AbstractList
b) LinkedList
c) ArrayList
d) AbstractSet

33. Which of this method is used to reduce the capacity of an ArrayList


object?
a) trim()
b) trimSize()
c) trimTosize()
d) trimToSize()

34. Standard output variable 'out' is defined which class?


a) PrintStream
b) IO
c) System
d) lang

35. Which of these keywords can be used to prevent inheritance of a


class?
a) final
b) constant
c) class
d) super

36. Which method is used in Java to get the values of an enum?


a) values()
b) getAllValues()
c) toArray()
d) toValues()

37. What will be the output?


class A extends Thread {
int i;
public void run()
{
i = 1;
}
public static void main(String[] args)
{
A a = new A();
a.start();
System.out.print(a.i);
}
}
a) runtime error
b) 0
c) 1
d) compilation error

38. What is multi threaded programming?


a) It’s a process in which two different processes run simultaneously.
b) It’s a process in which two or more parts of same process run
simultaneously.
c) Its a process in which many different process are able to access same
information.
d) Its a process in which a single process can access information from
many sources.

39. Which methods must be overridden to make a HashSet behave on


objects?
a) hashCode and equals
b) hashCode and compare
c) equals and toString
d) equals and compareTo

40. To compare whether two references point to the same object we use
a) both a and B.
b) .equals function
c) == operator
d) compareTo

You might also like