Saturday, February 13, 2021

Java Programming New 100 Solved MCQ Question Answer Part-1

Question: 1. Which of the following will produce a value of 22 if x=22.9:

Option A. Ceil(x)
Option B. Round(x)
Option C. Rint(x)
Option D. Abs(x)

Question: 2. If m and n are int type variables, what will be the result of the expression
'm % n' when m = -14 and n = -3?
Option A. 4
Option B. 2
Option C. -2
Option D. -4

Question: 3. Consider the following statements:
int x = 10, y = 15; 
x = ((x < y) ? (y + x) : (y - x);

What will be the value of x after executing these statements?
Option A. 25
Option B. 15
Option C. 5
Option D. Error can't be executed.

Question: 4. Which of the following will produce a value of 10 if x = 9.7?
Option A. floor(x)
Option B. abs(x)
Option C. rint(x)
Option D. round(x)

Question: 5. Which of the following control expressions are valid for an if statement?
Option A. an integer expression
Option B. a Boolean expression
Option C. either A or B
Option D. Neither A or B

Question: 6. Consider the following class definition.
Class Student extends String
{
}
What happens when we try to compile this class?
Option A. Will not compile because class body is not defined
Option B. Will not compile because class is not declared public
Option C. Will compile successfully.
Option D. Will not compile because String is abstract

Question: 7. What is wrong in the following class definitions? 
abstract class print { 
abstract show();
}
class Display extends print {
}
Option A. Nothing is wrong
Option B. Wrong Method show() should have a return type
Option C. Wrong Methods show() is not implemented in Display
Option D. Wrong Display does not contain any members.

Question: 8. What is error in the following class definitions? 
abstract class xy { 
abstract sum(int x, int y) {
}
}
Option A. class header is not define properly
Option B. constructor is no defined
Option C. method is not defined properly
Option D. no error

Question: 9. Consider the following class definitions:
 class maths { 
student student1;
}
class student {
String name;
}

This code represents:

Option A. an 'is a' relationship
Option B. a 'has a' relationship
Option C. both
Option D. neither

Question: 10. Which key word can protect a class in package from accessibility by the classes outside the package?
Option A. private
Option B. protected
Option C. final
Option D. don't use any keyword at all(make it default)

Question: 11. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
Option A. private
Option B. protected
Option C. public
Option D. private protected

Question: 12. The use of protected keyword to a member in a class will restrict its visibility as follows:
Option A. Visibility only in the class and its subclasses in the same package.
Option B. Visibility only inside the same package.
Option C. Visibility in all classes in the same package and subclasses in other packages.
Option D. Visibility only in the class where it is declared.

Question: 13. Which of the following are not keywords?
Option A. NULL
Option B. Implements
Option C. Protected
Option D. None of the above

Question: 14. Which of the following are keywords?
Option A. integer
Option B. default
Option C. Boolean
Option D. Object

Question: 15. Which of the following keywords are used to control access to a class member?
Option A. default
Option B. protected
Option C. interface
Option D. None of the above

Question: 16. The keywords reserved but not used in the initial version of Java re:
Option A. Synchronized
Option B. Boolean
Option C. union
Option D. goto

Question: 17. A package is a collection of
Option A. classes
Option B. interface
Option C. editing tools
Option D. classes and interfaces

Question: 18. Which of the following statements are true?
Option A. An abstract class may not have any final methods?
Option B. A final class may not have any abstracts methods.
Option C. Transient variables must be static.
Option D. all of the above

Question: 19. The concept of multiple inheritance is implemented in Java by
Option A. extending two or more classes
Option B. extending one class and implementing one or more interfaces
Option C. all the above

Question: 20. Which of the following statements are valid array declarations?
Option A. int number();
Option B. float average[];
Option C. double[] marks;
Option D. counter int[];

Question: 21. Which of the following classes are available in the java.lang package?
Option A. Random
Option B. Stack
Option C. String Buffer
Option D. Vector

Question: 22. Which of the following are the wrapper classes?
Option A. Random
Option B. Vector
Option C. Byte
Option D. all of the above

Question: 23. Which of the following methods belong to the String class?
Option A. length()
Option B. compareTo()
Option C. substring()
Option D. all of the them

Question: 24. Given the code
String s = new String("abc");
Which of the following calls are valid?
Option A. s.toUpperCase()
Option B. s.append("xyz")
Option C. s.setCharAt(1<'A')
Option D. all of the above

Question: 25. The methods wait() and noify() are defined in
Option A. java.lang.Thread
Option B. java.lang.Runnable
Option C. java.lang.Object
Option D. java.lang.ThreadGroup

Question: 26. When we invoke repaint () for a Component, the AWT invokes the method:
Option A. draw()
Option B. update()
Option C. show()
Option D. paint()

Question: 27. What does the following line of code do?
TextField text=new TextField(10);
Option A. Creates text object that can hold 10 rows of text.
Option B. Creates text object that can hold 10 columns of text.
Option C. Creates the object text and initializes it with the value 10.
Option D. The code is illegal.

Question: 28. Which of the following methods can be used to draw the outline of a square?
Option A. fillRect()
Option B. drawLine()
Option C. drawString()
Option D. all of the above

Question: 29. Which of the following methods can be used to change the size of a
size() *
resize()
Option A. component
Option B. dimension()
Option C. setSize()
Option D. size()

Question: 30. Which of the following methods can be used to remove a component from the display?
Option A. remove()
Option B. desappear()
Option C. hide()
Option D. move()

Question: 31. The setBackground() method is part of the class
Option A. Applet
Option B. Component
Option C. Container
Option D. Object

Question: 32. When we implement the Runnable interface, we must define the method
Option A. start()
Option B. init()
Option C. runnable()
Option D. run()

Question: 33. Which of the following string can be used as mode string for creating a RandomAccessFile object?
Option A. "rw"
Option B. "wr"
Option C. "0"
Option D. 'w''

Question: 34. DataInput is
Option A. An abstract class defined is java.io.
Option B. A class we can use to read primitive data types.
Option C. An interface that defines methods to open files.
Option D. An interface that defines methods to read primitive data types.

Question: 35. Which of the following statements are true?
Option A. UTF characters are all 24 bits.
Option B. Reader class has methods that can read integers and floats.
Option C. Unicode characters are all 16 bits.
Option D. all of the above

Question: 36. Which are the valid ways to create DataInputStream streams?
Option A. new DataInputStream(new File("in.dat"));
Option B. new DataInputStream(new FileInputStream("in.dat"));
Option C. new DataInputStream("in.dat");
Option D. new DataInputStream("in.data","r");

Question: 37. Which exception is thrown by the read() method of InputStream class?
Option A. IOException
Option B. FileNotFoundException
Option C. ReadException
Option D. None of the above

Question: 38. In the code below, what data types the variable x can have?
Option A. byte b1 = 5;
Option B. byte b2 = 10;
Option C. x = b1 * b2;
Option D. int short

Question: 39. If you want to assign a value of 99 to the variable year, then which of the following lines can be used within an <applet> tags?
Option A. number=getParameter(99)
Option B. <number==99>
Option C.
Option D. <param = radius value ==99>

Question: 40. What is java -g used for?
Option A. Using the jdb tool
Option B. Executing a class with optimization turned off
Option C. To provided information about deprecated methods
Option D. Non of the above

Question: 41. With javadoc, which of the following denotes a javadoc comment?
Option A. //#
Option B. /*
Option C. /**
Option D. //**

Question: 42. Give file is a file object, which of the following are legal statements to create a new file.
Option A. file.create();
Option B. FileOutputStream fos=new FileOutputStream(file);
Option C. FileInputStream fis=new FileInputStream(file);
Option D. all of the above

Question: 43. Which javadoc tag is used to denote a comment for methods parameters?
Option A. @method
Option B. @parameter
Option C. @argument
Option D. @param

Question: 44. Which of the following command lines options generates documentation for all classes and methods?
Option A. -protected
Option B. -public
Option C. -private
Option D. -encoding

Question: 45. Which of the following represent legal flow control statements?
Option A. break;
Option B. break();
Option C. continue(inner);
Option D. all of the above

Question: 46. Consider the following code snippet:
try 
{
int x=0; int y=50/x;
System.out.println("Division by zero");
}
catch(ArithmeticException e)
{
System.out.println("catch block");
}

What will be the output?
Option A. Error. Won't compile
Option B. Division by zero
Option C. Catch block
Option D. Division by zero catch block

Question: 47. Which of the following represent legal flow control statements?
Option A. break();
Option B. continue(inner);
Option C. return;
Option D. exit();

Question: 48. The name of a Java program file must match the name of the class with the extension Java.
Option A. True
Option B. False

Question: 49. Two methods cannot have the same name in Java.
Option A. True
Option B. False

Question: 50. The modulus operator (%) can be used only with Integer operands.
Option A. True
Option B. False

Question: 51. Declarations can appear anywhere in the body of a Java method.
Option A. True
Option B. False

Question: 52. All the bitwise operators have the same level of precedence in Java.
Option A. True
Option B. False

Question: 53. When X is a positive number the operations x>> 2 and x>>>2 both produce the same result.
Option A. True
Option B. False

Question: 54. If a=10 and b= 15, then the statement x =(a>b)?a:b; assigns the value 15 to x.
Option A. True
Option B. False

Question: 55. In evaluating a logical expression of type 'Boolean expression 1&& Boolean expression 2', both the Boolean expressions are not always evaluated.
Option A. True
Option B. False

Question: 56. The default case is always required in the switch selection structure.
Option A. True
Option B. False

Question: 57. The break statement is required in the default case of a switch selection structure.
Option A. True
Option B. False

Question: 58. The expression (x == y && a<b) is true If either x == y is true or a<b is true.
Option A. True
Option B. False

Question: 59. A variable declared inside the for loop control can not be referenced out side the loop.
Option A. True
Option B. False

Question: 60. Java always provides a default constructor to a class.
Option A. True
Option B. False

Question: 61. When present, package must be the first no comment statement in the file.
Option A. True
Option B. False

Question: 62. The import statement is always the first no comment statement in a Java program files.
Option A. True
Option B. False

Question: 63. Objects are passed to a method by use of call-by-reference.
Option A. True
Option B. False

Question: 64. It is perfectly legal to refer to any instance variable inside of a static method.
Option A. True
Option B. False

Question: 65. When we implement an interface method, it should be declared as public.
Option A. True
Option B. False

Question: 66. We can over load methods with differences only in their return type.
Option A. True
Option B. False

Question: 67. It is an error to have a method with the same signature in both the super class and its subclass.
Option A. True
Option B. False

Question: 68. A constructor must always invoke its supper class constructor in its first statement.
Option A. True
Option B. False

Question: 69. Any class may be inherited by another class in the same package.
Option A. True
Option B. False

Question: 70. Any method in a supper class can be over ridden in its subclass.
Option A. True
Option B. False

Question: 71. One the features of is that an array can store many different types of values.
Option A. True
Option B. False

Question: 72. An individual array element that is passed to a method and modified in that method will contain the modified value when the called method completes execution.
Option A. True
Option B. False

Question: 73. Members of a class specified as private are accessible only to the methods of the class.
Option A. True
Option B. False

Question: 74. A method declared as static can not access non-static class members.
Option A. True
Option B. False

Question: 75. A static class method can be invoked by simply using the name of the method alone.
Option A. True
Option B. False

Question: 76. It is an error if a class with one or more abstract methods is not explicitly declared abstract.
Option A. True
Option B. False

Question: 77. It is perfectly legal to assign a subclass object to a supper class reference.
Option A. True
Option B. False

Question: 78. Every method of a final in class is implicitly final.
Option A. True
Option B. False

Question: 79. All methods in an abstract class must be declared abstract.
Option A. True
Option B. False

Question: 80. When the string objects are compared with ==, the result is true If the strings contain the same values.
Option A. True
Option B. False

Question: 81. A string object can not be modified after it is created.
Option A. True
Option B. False

Question: 82. The length of a string object 's1' can be obtained using the expression s1.length.
Option A. True
Option B. False

Question: 83. A catch can have comma-separated multiple arguments.
Option A. True
Option B. False

Question: 84. It is an error to catch the same type of exception in two different catch blocks associated with a particular try block.
Option A. True
Option B. False

Question: 85. Throwing an exception always causes program termination.
Option A. True
Option B. False

Question: 86. Every call to wait has a corresponding call to notify that will eventually end the wafting.
Option A. True
Option B. False

Question: 87. Declaring a method synchronized guarantees that the deadlock cannot occur.
Option A. True
Option B. False

Question: 88. The programmer must explicitly create the system .in and system .out objects.
Option A. True
Option B. False

Question: 89. To delete a file, we can use an instance of class file.
Option A. True
Option B. False

Question: 90. A panel can not be added to another panel.
Option A. True
Option B. False

Question: 91. Frames and applets cannot be used together in the same program.
Option A. True
Option B. False

Question: 92. A final class may not have any abstract method.
Option A. True
Option B. False

Question: 93. A class may be both abstract and final.
Option A. True
Option B. False

Question: 94. A thread can make second thread ineligible for execution by calling the suspend (-) method on second thread.
Option A. True
Option B. False

Question: 95. A Java monitor must either extend thread class or implement Runnable interface.
Option A. True
Option B. False

Question: 96. The check box group class is a subclass of the component class.
Option A. True
Option B. False

Question: 97. If a=10 and b= 15, then the statement x =(a>b)?a:b; assigns the value 15 to x.
Option A. True
Option B. False

Question: 98. Java is fully object oriented programme.
Option A. true
Option B. false

Question: 99. For all insert, update, delete, query operations on a database, ResultSet object creation is mandatory.
Option A. True.
Option B. False.

Question: 100. forName() is a static factory method
Option A. True
Option B. False

Answer Sheet

1C
2C
3A
4D
5B
6D
7C
8C
9B
10D
11D
12C
13A
14B
15B
16D
17D
18B
19B
20B
21A
22C
23D
24A
25C
26B
27B
28B
29C
30C
31B
32D
33A
34D
35C
36B
37A
38D
39C
40B
41C
42B
43D
44C
45A
46C
47C
48A
49B
50B
51A
52A
53A
54A
55A
56B
57B
58B
59A
60B
61A
62B
63A
64B
65A
66B
67B
68B
69B
70B
71B
72B
73A
74A
75B
76A
77A
78A
79B
80B
81A
82B
83B
84A
85B
86A
87A
88B
89A
90B
91B
92A
93B
94A
95B
96B
97A
98A
99B
100A

0 comments:

Post a Comment