Java-Programming (Set 1)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Java Programming

1 of 7 sets

1. Who is considered as the creator of JAVA ?


A. Dennis Richie
B. Ken Thompson
C. James Gosling
D. Bjarne Stroupstrup
Answer:C

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


A. Java supports only Procedural Oriented Programming approach

o m
B. Both Procedural and Object Oriented Programming are supported in Java

. c
C. Java supports only Object Oriented Programming approach
D. None of the Above
te
Answer:B a
q M
3. JRE stands for
c
A. Java Realtime Environment
B. Java Rapid Enterprise
M
C. Java Runtime Environment
D. None of the above
Answer:C

4. Java source files are compiled and converted to


A. Object code
B. machine code
C. Bytecode
D. executable file
Answer:C

5. JVM is ___________for bytecode.


A. a compiler
B. an interpreter
C. assembler
D. none of the above
Answer:B

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


A. 1 bytes
B. 2 bytes
C. 4 bytes
D. 8 bytes
Answer:C

7. Which is a valid float literal?


A. 1.23
B. 2
C. 1.23d
D. 1.23f
Answer:D

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


A. -128 to 127
B. 0 to 256
C. 0 to 32767
D. 0 to 65535
Answer:D

9. Which of these coding types is used for data type char in Java?
A. ASCII
B. ISO-LATIN-1
C. UNICODE
D. None of the mentioned
Answer:C

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


A. True & False

View all MCQ's at McqMate.com


B. 0 & 1
C. Any integer value.
D. Both a & b
Answer:A

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


A. x1
B. 1x
C. $x
D. x 1
Answer:A

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


A. <<
B. >>
C. <<<
D. >>>
Answer:D

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


A. goto
B. jump
C. break
D. if
Answer:C

14. Which of these operators is used to allocate memory to array variable in Java?
A. malloc
B. alloc
C. new
D. new malloc
Answer:C

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

View all MCQ's at McqMate.com


B. while
C. for
D. None of the mentioned
Answer:A

16. Which of these is necessary condition for automatic type conversion in Java?
A. The destination type is smaller than source type.
B. The destination type is larger than source type.
C. The destination type can be larger or smaller than source type.
D. None of the mentioned
Answer:B

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


A. b can not store the result 2500, limited by its range.
B. * operator has converted b * 50 into int, which can not be converted to byte without casting.
C. b can not contain value 50.
D. No error in this code
Answer:B

18. Which of these is an incorrect array declaration?


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

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


A. if
B. switch
C. Both a & b
D. None of the mentioned
Answer:B

20. Which of these are selection statements in Java?


A. if

View all MCQ's at McqMate.com


B. for
C. continue
D. all of these
Answer:A

21. Which of these jump statements can skip processing remainder of code in its
body for a particular iteration?
A. break
B. return
C. exit
D. continue
Answer:D

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


A. 2
B. 3
C. 6
D. 5
Answer:A

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


A. 2
B. 32
C. 1 6
D. 5
Answer:B

24. The keyword used to create a constant variable


A. const
B. static
C. final
D. none of these
Answer:C

25. What is stored in the object obj in following lines of code? box obj;
A. Memory address of allocated memory of object.

View all MCQ's at McqMate.com


B. NULL
C. Any arbitrary pointer
D. Garbage
Answer:B

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


A. Box obj = new Box();
B. Box obj = new Box;
C. obj = new Box();
D. new Box obj;
Answer:A

27. Name the keyword that makes a variable belong to a class, rather than being
defined for each instance of the class.
A. static
B. final
C. abstract
D. public
Answer:A

28. Variables declared with in a class are called


A. Identifier
B. local variable
C. instance variable
D. global variable
Answer:C

29. Variables declared within a method or block are called


A. Static variable
B. local variable
C. instance variable
D. global variable
Answer:B

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

View all MCQ's at McqMate.com


B. method overloading
C. Dynamic method dispatch
D. none of the above
Answer:B

31. _________ is used to initialize objects.


A. Methods
B. arguments
C. constructors
D. new keyword
Answer:C

32. What is the return type of Constructors?


A. int
B. float
C. void
D. None of the mentioned
Answer:D

33. Which of the following is a method having same name as that of its class?
A. finalize
B. delete
C. class
D. constructor
Answer:D

34. Which operator is used by Java run time implementations to free the memory
of an object when it is no longer needed?
A. delete
B. free
C. new
D. None of the mentione
Answer:D

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

View all MCQ's at McqMate.com


B. public
C. protected
D. None of the mentioned
Answer:B

36. Which of these is used to access member of class before object of that class is
created?
A. public
B. private
C. static
D. protected
Answer:C

37. The keyword used to create an object


A. class
B. this
C. new
D. malloc
Answer:C

38. The keyword used to refer the current object


A. class
B. this
C. new
D. malloc
Answer:B

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


A. destructor
B. terminate()
C. finalize()
D. destroy()
Answer:C

40. Which class cannot have a subclass in java


A. abstract class

View all MCQ's at McqMate.com


B. parent class
C. final class
D. None of above
Answer:C

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


A. Inherits
B. extends
C. implements
D. import
Answer:B

42. The use of final keyword with method definition


A. Supports method overriding
B. implements dynamic method dispatch
C. Prevents method overriding
D. none of these
Answer:C

43. Identify the type of inheritance when two or more subclasses inherit the
properties of a super class.
A. Multiple inheritance
B. Single inheritance
C. Multilevel inheritance
D. Hierarchical inheritance
Answer:D

44. The keyword used inside a class to refer to its immediate super class is
A. super
B. parent
C. base
D. none of these
Answer:A

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


A. Abstract constructors cannot be created.

View all MCQ's at McqMate.com


B. Abstract classes can not be inherited.
C. An abstract class contains only abstract methods.
D. All of the above.
Answer:A

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


A. abst
B. abstract
C. Abstract
D. abstract class
Answer:B

47. If a class inheriting an abstract class does not define all of its function then it
will be known as?
A. abstract
B. A simple class
C. Static class
D. None of the mentioned
Answer:A

48. Which of these is not a correct statement?


A. Every class containing abstract method must be declared abstract.
B. Abstract class defines only the structure of the class not its implementation.
C. Abstract class can be initiated by new operator.
D. Abstract class can be inherited.
Answer:C

49. Which method defined in Integer class can be used to convert a whole number
in string type to primitive int type.
A. valueOf()
B. intValue()
C. parseInt()
D. getInteger()
Answer:C

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

View all MCQ's at McqMate.com


A. System
B. Root
C. Math
D. Arithmetic
Answer:C

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


A. By value
B. by reference
C. both a & b
D. none of these
Answer:A

52. Which of these is used as default for a member of a class if no access specifier is
used for it?
A. private
B. public
C. public, within its own package
D. protected
Answer:C

53. Which of these keywords is used to refer to member of base class from a sub
class?
A. upper
B. super
C. this
D. None of the mentioned
Answer:B

54. 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 A {}
D. class B extends class A {}
Answer:C

View all MCQ's at McqMate.com


55. Which of the following are true about interfaces.
A. Methods declared in interfaces are implicitly private.
B. Variables declared in interfaces are implicitly public, static, and final.
C. An interface contains any number of method definitions.
D. The keyword implements indicate that an interface inherits from another.
Answer:B

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


A. interface
B. Interface
C. intf
D. implements
Answer:A

57. Which of these can be used to fully abstract a class from its implementation?
A. Objects
B. Packages
C. Interfaces
D. None of the Mentione
Answer:C

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


A. Public
B. Protected
C. private
D. All of the mentioned
Answer:A

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


previously?
A. import
B. Import
C. implements
D. Implements
Answer:C

View all MCQ's at McqMate.com


60. Which of the following is correct way of implementing an interface salary by
class manager?
A. class Manager extends salary {}
B. class Manager implements salary {}
C. class Manager imports salary {}
D. None of the mentioned
Answer:B

61. The keyword used to create a package is


A. import
B. package
C. classpath
D. public
Answer:B

62. The modifier which specifies that the member can only be accessed in its own
class is
A. public
B. private
C. protected
D. none
Answer:B

63. Which of the following package stores all the standard java classes? a) jav
A. lang
B. java
C. java.util
D. java.packages
Answer:A

64. Which of these is a mechanism for naming and visibility control of a class and
its content?
A. Object
B. Packages
C. Interfaces
D. None of the Mentioned

View all MCQ's at McqMate.com


Answer:B

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?
A. Public
B. Protected
C. No Modifier
D. All of the mentioned
Answer:A

66. Which of the following is correct way of importing an entire package ‘pkg’?
A. import pkg.
B. Import pkg.
C. import pkg.*
D. Import pkg.*
Answer:C

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


A. Package defines a namespace in which classes are stored.
B. A package can contain other package within it.
C. Java uses file system directories to store packages.
D. A package can be renamed without renaming the directory in which the classes are stored.
Answer:D

68. Which of these method of class String is used to extract a single character from
a String object?
A. CHARAT()
B. chatat()
C. charAt()
D. ChatAt()
Answer:C

69. Which of these method of class String is used to obtain length of String object?
A. get()
B. Sizeof()
C. lengthof()

View all MCQ's at McqMate.com


D. length()
Answer:D

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


A. try
B. finally
C. thrown
D. catch
Answer:C

71. The code within the ----------- block will always be executed whether or not an
exception is thrown.
A. try..catch
B. finally
C. throw
D. throws
Answer:B

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


A. try..catch
B. finally
C. throw
D. throws
Answer:A

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


A. try
B. finally
C. throw
D. catch
Answer:C

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

View all MCQ's at McqMate.com


C. None of these
D. a & b
Answer:B

75. Which of these classes is related to all the exceptions that cannot be caught?
A. Error
B. Exception
C. None of these
D. a & b
Answer:A

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


A. IOException
B. InterruptedException
C. SystemException
D. SystemInputException
Answer:A

77. Which is the super class of all exception classes


A. Exception
B. Object
C. Error
D. Throwable
Answer:D

78. Which class is the super class of all classes of the java.lang package?
A. Object
B. System
C. Super
D. Class
Answer:A

79. Which of the following exception is raised when a number is divided by zero
A. NumberFormatException
B. ArithmeticException

View all MCQ's at McqMate.com


C. NullPointerException
D. IllegalArgumentException
Answer:B

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


A. finally
B. catch
C. catch or finally
D. None of the mentioned
Answer:C

81. Which of these exceptions will occur if we try to access the index of an array
beyond its length?
A. ArithmeticException
B. ArrayException
C. ArrayIndexException
D. ArrayIndexOutOfBoundsException
Answer:D

82. Runnable is a
A. Class
B. Method
C. Variable
D. Interface
Answer:D

83. Thread priority in Java is represented as?


A. int
B. Float
C. double
D. long
Answer:A

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


A. String
B. System

View all MCQ's at McqMate.com


C. Thread
D. Runnable
Answer:C

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


A. Runnable
B. Connections
C. Set
D. MapConnections
Answer:A

86. 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()
Answer:C

87. Which of this method of Thread class is used to change the state of a thread to
blocked state?
A. sleep()
B. terminate()
C. stop()
D. block()
Answer:A

88. Which method in Thread class is used to check weather a thread is still
running?
A. isAlive()
B. Join()
C. isRunning()
D. Alive()
Answer:A

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

View all MCQ's at McqMate.com


A. run()
B. start()
C. runThread()
D. startThread()
Answer:B

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


A. sleep()
B. isAlive()
C. join()
D. stop()
Answer:C

91. Which of these is used to read a string from the input stream?
A. get()
B. getLine()
C. read()
D. readLine()
Answer:D

92. Which of these classes is used to read characters and strings in Java from
console?
A. BufferedReader
B. StringReader
C. BufferedStreamReader
D. InputStreamReader
Answer:D

93. Which of these classes are used by Byte streams for input operation?
A. InputStream
B. InputOutputStream
C. Reader
D. All of the mentioned
Answer:A

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

View all MCQ's at McqMate.com


A. System
B. System.out
C. BufferedOutputStream
D. PrintStream
Answer:D

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


A. printout()
B. println()
C. write()
D. All of the mentioned
Answer:B

96. Which of these classes are used by character streams output operations?
A. OutputStream
B. Writer
C. ReadStream
D. InputOutputStream
Answer:B

97. Which refers to a channel through which data flow from the source to the
destination:
A. String
B. Character
C. Stream
D. Buffer
Answer:C

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


A. Byte and Character Stream Classes
B. Stream and String Classes
C. String and Character Stream Classes
D. Buffer and Character Stream Classes
Answer:A

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

View all MCQ's at McqMate.com


A. 8 bit
B. 16 bit
C. 32 bit
D. 64 bit
Answer:A

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


characters:
A. 8 bit Unicode
B. 16 bit Unicode
C. 32 bit Unicode
D. 64 bit Unicode
Answer:B

View all MCQ's at McqMate.com

You might also like