Quiznetik

Java Programming | Set 1

1. Who is considered as the creator of JAVA ?

Correct : C. James Gosling

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

Correct : C. Java supports only Object Oriented Programming approach

3. JRE stands for

Correct : C. Java Runtime Environment

4. Java source files are compiled and converted to

Correct : C. Bytecode

5. JVM is ___________for bytecode.

Correct : B. an interpreter

6. What is the size of int data type in java?

Correct : C. 4 bytes

7. Which is a valid float literal?

Correct : D. 1.23f

8. What is the numerical range of a char in Java?

Correct : D. 0 to 65535

9. Which of these coding types is used for data type char in Java?

Correct : C. UNICODE

10. Which of these values can a boolean variable contain?

Correct : A. True & False

11. Which one of the following is a valid identifier in java?

Correct : A. x1

12. Which operator is used to implement unsigned right shift of an integer?

Correct : D. >>>

13. Which one of the following is a jump statement in java?

Correct : C. break

14. Which of these operators is used to allocate memory to array variable in Java?

Correct : C. new

15. Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

Correct : A. do-while

16. Which of these is necessary condition for automatic type conversion in Java?

Correct : B. The destination type is larger than source type.

17. What is the error in this code? byte b = 50; b = b * 50;

Correct : B. * operator has converted b * 50 into int, which can not be converted to byte without casting.

18. Which of these is an incorrect array declaration?

Correct : D. int arr[] = int [5] new

19. Which of these selection statements test only for equality?

Correct : B. switch

20. Which of these are selection statements in Java?

Correct : A. if

21. Which of these jump statements can skip processing remainder of code in its body for a particular iteration?

Correct : D. continue

22. What is the value of the expression 2 & 3 ?

Correct : A. 2

23. What is the value of the expression 8 << 2 ?

Correct : B. 32

24. The keyword used to create a constant variable

Correct : C. final

25. What is stored in the object obj in following lines of code? box obj;

Correct : B. NULL

26. Which of the following is a valid declaration of an object of class Box?

Correct : A. Box obj = new Box();

27. Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class.

Correct : A. static

28. Variables declared with in a class are called

Correct : C. instance variable

29. Variables declared within a method or block are called

Correct : B. local variable

30. Defining methods with same name and different no. of parameters are called

Correct : B. method overloading

31. _________ is used to initialize objects.

Correct : C. constructors

32. What is the return type of Constructors?

Correct : D. None of the mentioned

33. Which of the following is a method having same name as that of its class?

Correct : D. constructor

34. Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?

Correct : D. None of the mentione

35. Which of these access specifiers must be used for main() method?

Correct : B. public

36. Which of these is used to access member of class before object of that class is created?

Correct : C. static

37. The keyword used to create an object

Correct : C. new

38. The keyword used to refer the current object

Correct : B. this

39. The method which is automatically invoked during garbage collection.

Correct : C. finalize()

40. Which class cannot have a subclass in java

Correct : C. final class

41. Which is the keyword used to inherit a class to another?

Correct : B. extends

42. The use of final keyword with method definition

Correct : C. Prevents method overriding

43. Identify the type of inheritance when two or more subclasses inherit the properties of a super class.

Correct : D. Hierarchical inheritance

44. The keyword used inside a class to refer to its immediate super class is

Correct : A. super

45. Which of the following is true in the case of abstract class

Correct : A. Abstract constructors cannot be created.

46. Which of these keywords are used to define an abstract class?

Correct : B. abstract

47. If a class inheriting an abstract class does not define all of its function then it will be known as?

Correct : A. abstract

48. Which of these is not a correct statement?

Correct : C. Abstract class can be initiated by new operator.

49. Which method defined in Integer class can be used to convert a whole number in string type to primitive int type.

Correct : C. parseInt()

50. The method sqrt() is defined in the class

Correct : C. Math

51. A primitive data type can be passed as an argument into a method

Correct : A. By value

52. Which of these is used as default for a member of a class if no access specifier is used for it?

Correct : C. public, within its own package

53. Which of these keywords is used to refer to member of base class from a sub class?

Correct : B. super

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

Correct : C. class B extends A {}

55. Which of the following are true about interfaces.

Correct : B. Variables declared in interfaces are implicitly public, static, and final.

56. Which of these keywords is used to define interfaces in Java?

Correct : A. interface

57. Which of these can be used to fully abstract a class from its implementation?

Correct : C. Interfaces

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

Correct : A. Public

59. Which of these keywords is used by a class to use an interface defined previously?

Correct : C. implements

60. Which of the following is correct way of implementing an interface salary by class manager?

Correct : B. class Manager implements salary {}

61. The keyword used to create a package is

Correct : B. package

62. The modifier which specifies that the member can only be accessed in its own class is

Correct : B. private

63. Which of the following package stores all the standard java classes? a) jav

Correct : A. lang

64. Which of these is a mechanism for naming and visibility control of a class and its content?

Correct : B. Packages

65. Which of this access specifies can be used for a class so that its objects can be created by a different class in another package?

Correct : A. Public

66. Which of the following is correct way of importing an entire package ‘pkg’?

Correct : C. import pkg.*

67. Which of the following is incorrect statement about packages?

Correct : D. A package can be renamed without renaming the directory in which the classes are stored.

68. Which of these method of class String is used to extract a single character from a String object?

Correct : C. charAt()

69. Which of these method of class String is used to obtain length of String object?

Correct : D. length()

70. Which of these keywords is not a part of exception handling?

Correct : C. thrown

71. The code within the ----------- block will always be executed whether or not an exception is thrown.

Correct : B. finally

72. Which of these keywords must be used to monitor for exceptions?

Correct : A. try..catch

73. Which of these keywords is used to manually throw an exception?

Correct : C. throw

74. Which of these classes is related to all the exceptions that can be caught by using catch?

Correct : B. Exception

75. Which of these classes is related to all the exceptions that cannot be caught?

Correct : A. Error

76. Which exception is thrown by read() method?

Correct : A. IOException

77. Which is the super class of all exception classes

Correct : D. Throwable

78. Which class is the super class of all classes of the java.lang package?

Correct : A. Object

79. Which of the following exception is raised when a number is divided by zero

Correct : B. ArithmeticException

80. A single try block must be followed by which of these?

Correct : C. catch or finally

81. Which of these exceptions will occur if we try to access the index of an array beyond its length?

Correct : D. ArrayIndexOutOfBoundsException

82. Runnable is a

Correct : D. Interface

83. Thread priority in Java is represented as?

Correct : A. int

84. Which of these class is used to make a thread?

Correct : C. Thread

85. Which of these interface is implemented to create a Thread?

Correct : A. Runnable

86. Which of these method of Thread class is used to find out the priority given to a thread?

Correct : C. getPriority()

87. Which of this method of Thread class is used to change the state of a thread to blocked state?

Correct : A. sleep()

88. Which method in Thread class is used to check weather a thread is still running?

Correct : A. isAlive()

89. Which of these methods is used to begin the execution of a thread?

Correct : B. start()

90. Which of these method waits for the thread to treminate?

Correct : C. join()

91. Which of these is used to read a string from the input stream?

Correct : D. readLine()

92. Which of these classes is used to read characters and strings in Java from console?

Correct : D. InputStreamReader

93. Which of these classes are used by Byte streams for input operation?

Correct : A. InputStream

94. Which of these class contains the methods print() & println()?

Correct : D. PrintStream

95. Which of these methods can be used to write console output?

Correct : B. println()

96. Which of these classes are used by character streams output operations?

Correct : B. Writer

97. Which refers to a channel through which data flow from the source to the destination:

Correct : C. Stream

98. Java Stream classes can be categorized into two groups:

Correct : A. Byte and Character Stream Classes

99. Byte Stream Classes support input/output operations on _____

Correct : A. 8 bit

100. Character Stream Classes support input/output operations on _______ characters:

Correct : B. 16 bit Unicode