Java Written exam choose the following questions and Answers

1. What is the meaning of the return data type void?
A) Void returns no data type.

2. A lower precision can be assigned to a higher precision value in Java. For example a byte type data can be assigned to int type.
A) True


3. Which of the following statements about the Java language is true?

Both procedural and OOP are supported in Java.
Java supports only procedural approach towards programming.
Java supports only OOP approach.
None of the above.

A)  Both procedural and OOP are supported in Java.

4. Which of the following statements is false about objects?

An instance of a class is an object
Objects can access both static and instance data
Object is the super class of all other classes
Objects do not permit encapsulation

A)  Objects do not permit encapsulation

5. Which methods can access to private attributes of a class?
A) Only methods those defined in the same class

6. What is an aggregate object?
A)  An instance which has other objects

7. Assume that File is an abstract class and has toFile() method. ImageFile and BinaryFile are concrete classes of the abstract class File.

Also, assume that the method toFile() is implemented in both Binary File and Image File. A File references an ImageFile object in memory and the toFile method is called, which implementation method will be called?
A) Image file

8. A class can have many methods with the same name as long as the number of parameters or type of parameters is different. This OOP concept is known as
A) Methos overloading

9. Which of the following is considered as a blue print that defines the variables and methods common to all of its objects of a specific kind?
A) Class

10. What are the two parts of a value of type double?
A) Significant Digits, Exponent

11. After the following code fragment, what is the value in fname?

String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
A) -1

12. What is the value of ‘number’ after the following code fragment execution?

int number = 0;
int number2 = 12
while (number < number2)
{
number = number + 1;
}
A) 12

13. Given the following code snippet;

int salaries[];
int index = 0;
salaries = new int salaries[4];
while (index < 4)
{
salaries[index] = 10000;
index++;
}
What is the value of salaries [3]?
A)  10000

14. Which of the following is not a return type?

boolean
void
public
Button
1.       A) Public

15. If result = 2 + 3 * 5, what is the value and type of ‘result’ variable?
A) 17,int

16. What is the data type for the number 9.6352?
A) double

17. Assume that the value 3929.92 is of type ‘float’. How to assign this value after declaring the variable ‘interest’ of type float?
A) interest = 3929.92f


          18. Which of the following statements is true?

         The default char data type is a space( ‘ ‘ ) character.
         The default integer data type is ‘int’ and real data type is ‘float’
         The default integer data type is ‘long’ and real data type is ‘float’
         The default integer data type is ‘int’ and real data type is ‘double’

A) The default integer data type is ‘int’ and real data type is ‘double’

19. How many numeric data types are supported in Java?
A) 6


20. Which of the following statements declare class Sample to belong to the payroll.admindept package?

package payroll;package admindept;
import payroll.*;
package payroll.admindept.Sample;
import payroll.admindept.*;
package payroll.admindept;

A) package payroll.admindept;

21. The class java.lang.Exception is
A) extends Throwable
22. Which of the following statements is true?

An exception can be thrown by throw keyword explicitly.
An exception can be thrown by throws keyword explicitly.
A)    An exception can be thrown by throw keyword explicitly.


23. All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java
A) Fianl

24. The code snippet

if( "Welcome".trim() == "Welcome".trim() )
System.out.println("Equal");
else
System.out.println("Not Equal");

will
A) cause a compiler error

25. Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed?

String str = new String(“Java”);
char fourthChar = str.charAt(4);
A) throws StringIndexOutofBoundsException

26. Which of the following statements is preferred to create a string "Welcome to Java Programming"?

String str = “Welcome to Java Programming”
String str = new String( “Welcome to Java Programming” )
String str; str = “Welcome to Java Programming”
String str; str = new String (“Welcome to Java Programming” )

A)  String str = “Welcome to Java Programming”

27. Which of the following statements is true?

A super class is a sub set of a sub class
class ClassTwo extends ClassOne means ClassOne is a subclass
class ClassTwo extends ClassOne means ClassTow is a super class
the class Class is the super class of all other classes in Java.

A super class is a sub set of a sub class
28. What kind of thread is the Garbage collector thread is?
A)  Daemon thread

29. When a thread terminates its processing, into what state that thread enters?
A) Dead state

30. Which statement is true?

HashTable is a sub class of Dictionary
ArrayList is a sub class of Vector
LinkedList is a subclass of ArrayList
Vector is a subclass of Stack
A)     HashTable is a sub class of Dictionary
31. Which of these statements is true?

LinkedList extends List
AbstractSet extends Set
HashSet extends AbstractSet
WeakHashMap extends HashMap

A)  LinkedList extends List


32. Which of the following is synchronized?

Set
LinkedList
Vector
WeakHashMap

A)    Vector
33. Select all the true statements from the following.

AbstractSet extends AbstractCollection
AbstractList extends AbstractCollection
HashSet extends AbstractSet
Vector extends AbstractList
All of the above

A) HashSet extends AbstractSet

34. Which of the methods should be implemented if any class implements the Runnable interface?

start()
run()
wait()
notify() and notifyAll()
A)     Run()
35. A thread which has invoked wait() method of an object, still owns the lock of the object. Is this statement true or false?
A)  False

36. Which of the following is not a method of the Thread class.

public void run()
public void start()
public void exit()
public final int getPriority()
A)     Public void exit()

37. To execute the threads one after another
A the keyword synchronized is used

38. The object of DataInputStream is used to
A)  To covert binary stream into character stream

39. DataInputStream is an example of
A)  Filtered stream

Comments

Popular posts from this blog

Android Objective type Question and Answers

Android Questions and Answers for written exams

Android Interview questions