0% found this document useful (0 votes)
16 views

mcq 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

mcq 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction to Object Oriented b.

Both Assertion (A) and Reason (R) are true and Reason
(R) is not correct explanation of Assertion (A).
Programming concepts c. Assertion (A) is true and Reason (R) is false.
d. Assertion (A) is false and Reason (R) is true.
Multiple choice question: 12. Name the feature of java depicted in the picture.
1. Procedure Oriented Programming mainly uses
a. Top-down approach
b. Top-down and bottom-up approach
c. Bottom-up approach
d. None of these
2. ____is the feature using which one class acquires the a. Encapsulation b. Inheritance
properties of another class. c. Abstraction d. Polymorphism
a. Abstraction b. Inheritance 13. Name the principle of java depicted in the given image:
c. Encapsulation d. Polymorphism
3. The ability of a method or object to take on multiple forms
is called
a. Abstraction b. Inheritance
c. Encapsulation d.Polymorphism
4. An object has
a. Attributes b. State a. Abstraction b. Inheritance
c. Behavior d. All of these c. Polymorphism d. Data hiding
5. A class is …. 14. Name the feature of java depicted in the above picture.
a. An object factory b. A blueprint to create objects
c. A specification for objects d. All of these
6. ______represents an entity in the real-world with its
identity and behavior.
a. A class b. An object
c. A procedure d. A method
7. ______is a template to create similar objects that
share common characteristics and behavior. a) Encapsulation (b) Inheritance
a. A method b. A procedure (c) Abstraction (d) Dynamic Binding
c. An attribute d. class 15. Name the feature of java depicted in the adjoining
8. The values of an object's …………. represent the state of picture.
the object. (a) Abstraction
a. methods b. procedures (b) Encapsulation
c. Attributes d. classes (c) Inheritance
9. The terms object and……………are often interchangeable. (d) Polymorphism
a. instance b. Behaviour
c. attribute d. State
10. Name the feature of java depicted in the picture. 16. Name the feature of java depicted in the adjoining
picture
(a) class (b) object
(c) object factory (d) Polymorphism

a. Data abstraction b. Polymorphism


c. Inheritance d. encapsulation
11. Assertion (A): A class is known as object factory.
Reason (R): Objects are created from class which 17. Name the feature of java depicted in the adjoining
contain common attributes and behavior. picture.
a. Both Assertion (A) and Reason (R) are true and Reason (a) class as a object factory
(R) is correct explanation of Assertion (A). (b) Encapsulation
(c) Inheritance
(d) Polymorphism (d) Need a linker
5. Java uses _______ for execution.
(a) Compiler and interpreter (b) Interpreter only
(c) Compiler only (d) None of these
6. A program that translates code written in a high-level
language into machine code is called
(a) Assembler (b) Linker
(c) Compiler (d) None of these

18. Name the feature of java depicted in the adjoining 7. A program that translates an assembly language program
picture. into machine code is called a/an
(a) Abstraction (a) Assembler (b) Linker
(b) Encapsulation (c) Compiler (d) None of these
(c) Inheritance 8.Java is___________
(d) Polymorphism (a) Robust (b) Object oriented
(c) Secure (d) All of these
9. Java can be used to write.
(a) Stand-alone applications only
(b) Both stand-alone and internet applications
(c) Internet applications only
(d) None of these
10. Java applications can run on
(a) Windows platform (b) Macintosh platform
(c) UNIX platform (d) All of these
Elementary Concept of Objects and Classes
11. Which among the following doesn’t come under OOP
concept?
1. Java applications (a) Data hiding (b) Message passing
(a) Are platform dependent
(c) Platform independent (d) Data binding
(b) Don't need a platform to run
12. Which among the following, for a pure OOP language,
(c) Are platform independent
is true?
(d) Can't run on Windows
a) The language should follow at least 1 feature of OOP
2. JVM stands for
b) The language must follow only 3 features of OOP
(a) Java Visual Monitor (b) Java Video Monitor
c) The language must follow all the rules of OOP
(c) Java Virtual Monitor (d) Java Virtual Machine
d) The language should follow 3 or more features of OOP
3. JRE stands for
13. Which feature of OOP reduces the use of nested
(a) Java Runtime Editor
classes?
(b) Java Runtime Environment (a) Inheritance (b) Binding
(c) Java Runtime Expression
(c) Abstraction (d) Encapsulation
(d) Java Runtime Enabler
14. Which feature can be implemented using encapsulation?
4. Stand-alone Java applications for execution.
(a) Polymorphism (b) Overloading
(a) Need Java-compatible web browser
(c) Inheritance (d) Abstraction
(b) Need an assembler
(c) Don't need Java-compatible web browser

Values and data types


Multiple choice question:

1.ASCII stands for


(a) American Standard Code for Information Interchange
(b) American Simulated Code for Information Interchange
(c) American Standard Code for Interchange of Information
(d) American Standard Code for Interaction of Information
2. Which of the following is not a token?
(a) Keyword (b) Identifiers
(c) Operators (d) Procedure (b) -32768 to 32767
3. Which of the following is a keyword? (c) -128 to 127
(a) character (b) break (d) -2147483648 to 2147483647
(c) object (d) attribute
17. What is the default value of a `boolean` in
4. Which of the following is not a legal identifier?
Java?
(a)_age (b) $Amount
(a) true (b) false
(c) 9thClass (d) nullValue
5. Which of the following is an invalid integer? (c) 0 (d) null
a) 1999 (b) 1999999 18. Which of the following data types can store
(c) 199 99 (d) 199 the largest value?
6. Which of the following is not a character literal? (a) int (b) short
(a)‘\t’ (b) “\t” (c) byte (d) long
(c) ‘t’ (d) All of these 19. What is the result of the following expression:
7. Which of the following punctuators is the statement 7 / 2?
terminator in Java?
(a) 3.5 (b) 3
a) ; (b) .
(c) 4 (d) 2.5
(c) , (d) All of these
20. Which of the following is not a primitive data t
8. Which of the following is not a primitive data type
in Java? ype in Java?
(a) boolean (b) short (a) int (b) String
(c) float (d) class (c) float (d) double
9. Which of the following is the size of a long data 21. What is the maximum value of an `int` in
type in Java? Java?
(a) 32 bits (b) 64 bits (a) 2147483647 (b) 32767
(c) 8 bits (d) 4 byte (c) 255 (d) 65535
10. Which of the following is the size of a boolean data 22. Which data type would be most appropriate
type in Java?
for storing a value with a large range of
(a) 32 bits (b) 16 bits
decimal places?
(c) 8 bits (d) 16 bits
11. What is the default value of an `int` in Java? (a) float (b) double
(a) 0 (b) 1 (c) int (d) long
(c) null (d) -1 23. What is the size of the `boolean` data type in Java?
12. Which of the following is a valid Java data (a) 1 bit (b) 4 bits
type? (c) 8 bits (d) 32 bits
(a) float64 (b) int32 24. Which of the following is the correct way
(c) long (d) double8 to declare a variable of type `double`?
13. What is the size of the `char` data type in (a) double d; (b) double d = 10;
Java? (c) double d = 10.0f; (d) Both A and B
(a) 8 bits (b) 16 bits 25. What will be the output of the following code
(c) 32 bits (d) 64 bits snippet?
14. Which keyword is used to declare a constant byte a = 10;
in Java? short b = 20;
(a) final (b) static byte c = a + b;
(c) const (d) immutable System.out.println(c);
15. What will be the output of the following code? (a) 30 (b) 10
int a = 5; (c) none (d) error
double b = 2.0; 26. Which data type would be best to use to store the
System.out.println(a / b); address ?
(a) 2.5 (b) 2 (a) long (b) String
(c) 2.0 (d) Error (c) char (d) both a & c
16. What is the range of the `byte` data type in 27. What will be the result of the following operation:
Java? `5.0 / 2`?
(a) -128 to 128 (a) 2.5 (b) 2
(c) 2.0 (d) Error
28. Which of the following is not a valid identifier in 39. Which of the following is a valid way to declare an
Java? `int` variable?
(a) myVar (b) _myVar (a) int num; (b) int num = 10;
(c) 2myVar (d) myVar2 (c) int num = "10"; (d) Int num;
29. What will the following code print? 40. What is the minimum value of the `short` data type
int x = 7; in Java?
double y = 4.0; (a) -32768 (b) -128
System.out.println(x % y); (c) 0 (d) -2147483648
(a) 3 (b) 3.0 41. Which of the following will result in a compilation
(c) 1.0 (d) 1 error?
30. What is the default value of a reference type (a) int a = 10; (b) float b = 10.0;
variable in Java? (c) double c = 10.0; (d) boolean d = 10;
(a) 0 (b) false 42. What is the size of a `long` data type in Java?
(c) null (d) 1 (a) 8 bytes (b) 4 bytes
31. Which of the following data types is used to store (c) 2 bytes (d) 1 byte
long size decimal numbers? 43. What is the result of the following code?
(a) float (b) long int x = 4;
(c) float (d) none double y = 3.5;
32. The total amount of size in byte require to store the System.out.println(x * y);
given data? (a) 14.0 (b) 14
int a=1, b= ‘A’; (c) 7.0 (d) 12.0
where Ascii code of ‘A’ is 65 44. Which data type would be used to represent a
(a) 8 (b) 12 single Unicode character?
(c) 4 (d) 64 (a) char (b) int
33. What will be the output of the following code? (c) String (d) byte
double d = 7%5/2*3/5; 45. Which of the following is not a valid `float` literal?
System.out.println(d); (a) 1.0f (b) 1.0
(a) 2 (b) 0 (c) 1f (d) 1.0F
(c) 2.0 (d) 0.0 46. What is the default value of a `long` variable?
34. Which data type would you use for a variable that (a) 0L (b) 0
will hold only 'true' or 'false'? (c) null (d) 0.0
(a) boolean (b) int 47. What is the size of the `short` data type in Java?
(c) char (d) byte (a) 2 bytes (b) 4 bytes
35. Which of these is used to invoke the or access the (c) 8 bytes (d) 1 byte
member methods or package in the program 48. What will be the output of the following code?
(a) final (b) static char c = 'A';
(c) = (d) .(dot) System.out.println((int) c);
36. What will be the result of `3 % 4 * 2` in Java? (a) 65 (b) 97
(a) 3 (b) 11 (c) 0 (d) 10
(c) 6 (d) 12 48. Assertion(A): In java statements written in lower
37. Which of the following types is use to store Real case letter or upper-case letter are treated as the same.
type value in Java? Reason(R): Java is a case sensitive language.
(a) int (b) char a. Both Assertion and Reason are true and Reason is a
(c) double (d) byte correct explanation of Assertion
38. What will be the output of the following code? b. Both Assertion and Reason are true and Reason is
int a = 5; not a correct explanation of Assertion
double b = 10.5; c. Assertion is true and Reason is false
System.out.println(a + b); d. Assertion is false and Reason is true
(a) 15.5 (b) 15
(c) 10.5 (d) Error
Operators and Expression 15. The operator that does not check next conations if
the first condition is true
(a) == (b) ||
1. Which among the following is a relational operator? (c) ! (d) &&
(a) + (b) > 16. The statement i = i + 1 is equivalent to ...........
(c) * (d) / (a) i++ (b) i += 1
2. The && operator requires which among the (c) ++i (d) All of these
following conditions to be satisfied to represent a 17. For x = 5, the statement sum = ++x%--x+x*2
evaluates to ...........
success for two relations?
(a) sum = 12 (b) sum = 13
(a) Both should be satisfied (c) sum = 11 (d) sum = 15
(b) Any one should be satisfied. 18. System.out.prinln((1>0) && (1<0)? false: true);
(c) None of them are satisfied. evaluates to ...........
(d) None of these (a) 0 (b) 1
3. Which among the following is not a logical (c) false (d) true
operator? 19. The statement (1>0) || (‘1’<‘0’) evaluates to ...........
(a) && (b) || (a) true (b) false
(c) ! (d) <= (c) none (d) error
4. The statement a% 2 will result in what if the value of 20. The statement (1==1)? 1: 0 evaluates to ...........
a is an even number? (a) 1 (b) 0
(a) 0 (b) 1 (c) false (d) true
(c) Both a and b (d) None of these 21. The expression 17 % 4 gives the output ...........
5. Which among the following operators is used to (a) 4 (b) 3
check whether the two operands are equal or not? (c) 2 (d) 1
(a) Equals (b) = 22. Consider the following code snippet:
(c) == (d) None of these float x = 8.25F;
6. Which among the following forms of operators int y; y = (int) x;
works with three operands? What are the values of x and y?
(a) Unary (b) Binary (a) x= 8.25, y = 8 (b) x = 8.0, y = 8.0
(c) Ternary (d) None of these (c) x = 8, y = 8.25 (d) x = 8, y = 8
7. An operator taking only single operand for its 23. The expression 13 / 3 gives the output ...........
operation is called. (a) 4 (b) 3
(a) A unary operator (c) 0 (d) 1
(b) A binary operator 24. The statement System.out.println("six " + 3 + 3);
(c) A ternary operator gives the output ...........
(d) None of these (a) six 33 (b) six 6
8. Which one of the following is not a binary operator, (c) 33 six (d) 6 six
if &&, ||, ! is a logical operator? 25. The expression 4 + 8 % 2 gives the output ...........
(a) && (b) % (a) 6 (b) 8
(c) == (d) ! (c) 4 (d) None of these
9. Which one of the following is not a valid operator in 26. Implicit type conversion is also known as ...........
Java? (a) Automatic type conversion
(a) ++ (b) !== (b) Type promotion
(c) = (d) == (c) Widening conversion
10. For x = 5, the statement sum = ++x + 8 evaluates to (d) all the above
(a) sum = 13 (b) sum = 14 27. Assertion (A): Increment and decrement
(c) sum =15 (d) sum =16 operators are binary operators.
11. The statement (1>0) && (1<0) evaluates to Reason (R): Increment and decrement
(a) 0 (b) 1 operators require only one operand.
(c) false (d) true a. Both Assertion (A) and Reason (R) are true and
12. If a = 8 and b = 4, the value of a %= b is ........... Reason (R) is correct explanation of Assertion (A).
(a) 2 (b) 0 b. Both Assertion (A) and Reason (R) are true and
(c) 4 (d) 8 Reason (R) is not correct explanation of Assertion
13. Forceful conversion from one data type to another (A).
data type c. Assertion (A) is true and Reason (R) is false.
(a) Implicit type conversion d. Assertion (A) is false and Reason (R) is true.
(b) Narrowing 28. Assertion (A): Value of a variable is cannot be
(c) Type conversion fixed.
(d) Coercion Reason (R): Variable’s value can be fixed by
14. float a= 1.26f +9.35F; using the final keyword
System.out.println(a); a. Both Assertion (A) and Reason (R) are true and
(a) Error (b) 10.61f Reason (R) is correct explanation Assertion of (A).
(c) 10.61 (d) 1.26f9.35F
b. Both Assertion (A) and Reason (R) are true and (a) The syntax of the programming language is not
Reason (R) is not correct explanation of Assertion followed.
(A). (b) The program does not run properly or does not
c. Assertion (A) is true and Reason (R) is false.
execute at all.
d. Assertion (A) is false and Reason (R) is true.
(c) The program produces an incorrect result.
29. Assertion (A): In java true, false and null these three (d) All of the above
words are not considered to be keywords. 11. The Scanner class can be used to read input from
Reason (R): Keywords are the words which convey (a) a keyboard (b) a file
a special meaning to java compiler the constants are (c) a string (d) All of these
not considered as keywords. 12. int p=55/0;
a) Both Assertion (A) and Reason (R) are true and
Name the type of error in the given statement:
Reason is the correct explanation of
Assertion(A). (a) Syntax (b) Logical
b) Both Assertion (A) and Reason(R) are true and (c) Runtime (d) Executional
Reason(R) is not correct explanation of 13. Which of the following methods will accept a string
Assertion(A). by using a Scanner object?
c) Assertion (A) is false and Reason(R) is true (a) next( ) (b) next.read( )
d) Assertion (A) is true and Reason(R) is false (c) next.String( ) (d) next.char( )
30. Give the output: System.out.println( ‘Z’+ ‘E’+5);
14. Which of the following is a method of Java Scanner
(a) ZE5 (b) 90705
(c) 1221025 (d) 164 class?
(a) nextline( ) (b) nextLine( )
Java library
(c) Nextline( ) (d) NextLine( )
15. What will be the output of Math.cbrt(-625)?
1. Math.random() returns a double value r such that
(a) 25.0 (b) 0.0
(a) 0.0 <=r<1.0 (b) 0.0 <=r <=1.0
(c) -25.0 (d) error
(c) 0.0 <r<= 1.0 (d) 0.0<r<1.0
16. Given the following statements:
2. Give the output of Math.floor(46.6)?
int min = 1, max = 10; int range = max - min + 1;
(a) 46.5 (b) 47.0
int num = (int) (range * Math.random() + min);
(c) -46.0 (d) 46.0
The value of num will be in integer such that ...........
3. Which of the following is false to find a square of a
(a) 1 <= num <= 10 (b) 1 <= num < 10
number?
c) 1 < num <= 10 (d) 1 < num < 10
(a)Math.pow(a,2) (b) a*a
(c) Math.sqrt(a,2) (d) all of them
17. Assertion (A): Math.round() function is used to
4. What type of value is returned by Math.round( )?
round off the decimal value.
(a) int (b) float
Reason (R): It gives the integer type of value.
(c) double (d) char
a. Both Assertion (A) and Reason (R) are true and
5. Which of the following syntax is true to find the
Reason (R) is correct explanation Assertion of (A).
square root of a number?
b. Both Assertion (A) and Reason (R) are true and
(a) sqrt(a) (b) Math.sqrt(a)
Reason (R) is not correct explanation of Assertion
(c) Squareroot(a) (d) None
(A).
6. Name the package that is used for different
c. Assertion (A) is true and Reason (R) is false.
Mathematical functions.
d. Assertion (A) is false and Reason (R) is true.
(a) java.lang (b) java.Lang
(c) java.lang.Scanner (d) None
7. Which keyword do you use to include a class in your
program?
(a) import (b) export INPUT IN JAVA
(c) include (d) impart Multiple choice questions:
8. Which of the following is not a valid method of the 1. Missing a semicolon in a statement in what type of
Scanner class? error?
(a) next() (b) nextlnt() (a) Logical (b) Syntax
(c) nextLong() (d) nextInteger() (c) Runtime (d) No error
9. Which package would you import for the Scanner 2. The keyword used to call package in the program:
class?
(a) java.util.* (b) java.lang.* (a) extends (b) export
(c) java.io.* (d) java.*; (c) import (d) package
10. Errors occur in a program when 3. What value will Math.sqrt (Math. ceil (15.3)) return
(a) 16.0 (b) 16 CONDITIONAL CONSTRUCT
(c) 5.0 (d) 4.0
4. Assuming all the unseen code is correct, what kind of
1. The condition in the if statement return which kind
error is it?
(a) Syntax error (b) Runtime error of data type value?
(c) Logical error (d) None (a) int (b) short
5. Which of the following might make the Java compiler (c) boolean (d) char
report a syntax error in a particular line of a program? 2. What will be the output of the following code?
(a) The program is typed in the wrong font. int x = 10;
(b) The line contains a comma (,) instead of a dot (.). if !(x < 15) {
(c) It is caused by Java runtime. System.out.println("Less than 15");
(d) Program takes too long to compile.
} else {
6. Which of the following statement is true for logical
System.out.println("15 or more");
errors?
}
(a) The compiler does not detect these errors.
(b) There is no indication of error when the program is (a) Less than 15 (b) 15 or more
executed. (c) Error (d) Nothing
(c) The program may produce correct results for some input 3. What will be the output of the following code
data and wrong results for other input data. snippet?
(d) All of the above int x = 20;
7. Which keyword do you use to include a class in your if (x == 20) {
program? System.out.println("x is 20");
(a) import (b) export
} if (x > 10) {
(c) include (d) impart
System.out.println("x is greater than 10");
8. Which of the following is not a valid method of the
} else {
Scanner class?
(a) next() (b) nextInt() System.out.println("x is 10 or less");
(c) nextLong() (d) nextNumber() }
9. Default delimiter used in the Scanner class is ........... (a) x is 20 (b) x is greater than 1
(a) Comma (b) Whitespace (c) x is 10 or less (d) both a and b
(c) Colon (d) There is no default delimiter. 4. What is the result of this `if` statement?
10. Which package would you import to display the date and final int a = 5, b = 10;
time? if (++a > b) {
(a) java.util.* (b) java.Date.* System.out.println("a is greater than b");
(c) java.io.* (d)java.lang.*
} else if (a == b) {
11. Which package would you import for the Scanner class?
System.out.println("a is equal to b");
(a) java.util.* (b) java.awt.*
(c) java.io.* (d) java.lang.* } else {
12. Errors occur in a program when ........... System.out.println("a is less than b");
(a) Syntax of the programming language is not followed. }
(b) The program does not run properly or does not execute (a) a is greater than b (b) a is equal to b
at all. (c) a is less than b (d) Error
(c) The program produces an incorrect result. 5. What will be the output of the following code?
(d) All of the above int i = 5;
13. The Scanner class can be used to read input from ...........
if (i > 0) {
(a) a keyboard (b) a file
if (i < 10) {
(c) string (d) All of these
System.out.println("i is between 1 and 10");
14. Which of the following command is used take float
value as input where ob is the object name }
1- float value = Float.parseFloat(ob.readLine()); } else {
2- float value = ob.nextFloat(); System.out.println("i is not positive");
a. Only 1 b. Only 2 }
c. Both 1 and 2 d. None (a) i is between 1 and 10 (b) i is not positive
(c) Error (d) Nothing
6. What is the output of the following code?
int x = 6;
if (--x < 5) { System.out.println ("Values are not equal");
System.out.println("x is less than 5"); (a) Both values are equal
} else if (x < 15) { (b) Incorrect use of the == operator
(c) Values are not equal (d) No
System.out.println("x is less than 15");
output
} else {
16. Consider the following code snippet:
System.out.println("x is 15 or more");
if ( c > d) x = c; else x = d;
} Choose the correct option if the code mentioned above is
(a) x is less than 1 (b) x is less than 15 rewritten using the ternary operator:
(c) x is 15 or more (d) Error (a) x = (c >d) ? c : d; (b) x = (c >d) ? d : c;
7. If a, b and c are the sides of a triangle then which of the (c) x = (c >d) ? c : c; (d) x = (c >d) ? d : d;
following statements is true for: 17. if ((a > b) && (a > c)), then which of the following
if(a!=b && a!=c && b!=c) statements is true?
(a) Equilateral triangle (b) Scalene triangle (a) a is the largest number. (b) b is the largest number.
(c) Isosceles triangle (d) All of the above (c) c is the largest number.
8. Two arithmetic expressions can be compared with if (d) b is the smallest number.
statement, using:
(a) Arithmetic operator (b) unary operator 18. Consider the following code snippet:
(c) Ternary operator (d) Relational operator int val = 2; switch (val)
9. Which of the following is a conditional statement? {
(a) if (b) goto case 1: System.out.println("Case 1"); break;
(c) for (d) none case 2: System.out.println("Case 2"); break;
10. Which of the following statements accomplishes 'fall default: System.out.println("No match found"); break;
through'? }
(a) for statement (b) switch statement Which of the following statements is correct?
(c) if-else (d) none (a) case 1 will be executed.
11. Which of the following are conditional constructs? (b) case 2 will be executed.
(a) if-else (b) if-else-if ladder (c) default will be executed.
(c) switch statement (d) All of these (d) both case 1 and 2 will be executed.
12. Which operator cannot be used with if-else statement? 19. A sequence of statements enclosed between a pair of curly
(a) <= (b) || brackets is called
(c) && (d)? : (a) a compound statement (b) an empty statement
13. What will be the output of the following code? (c) a null statement (d) a void statement
int size = 2; 20. Which clause is optional in the switch statement?
if (size < 0) (a) switch (b) case
System.out.println("Small"); (c) default (d) None of these
else if !(size == 0) 21. Which of the following is used to stop the execution of if
System.out.println("Medium"); statement ?
else (a) break (b) continue
System.out.printIn("Large"); (c) both a & b (d) none
(a) Small (b) Medium 22. Which of the following causes a fall-through in the switch
(c) Large (d) Runtime error statement?
14. What will be the output of the following code? (a) the omission of fall (b) the omission of continue
int fruit = 3; (c) the omission of break (d) the omission of loop
switch (fruit + 1) 23. Which of the following is mandatory in the switch
{ statement?
case 1: System.out.println("Banana"); break ; (a) break (b) case
case 2: System.out.println("Apple"); break ; (c) continue (d) default
case 3: System.out.println("Orange"); break ; 24. Which of the following statement is a valid combination?
default: System.out.println("Fruitless"); (a) if inside switch (b) switch inside if
} (c) else inside switch (d) both a and b
(a) Orange (b) Banana 25. If m, n, p are the three integers, then which of the
(c) Apple (d) Fruitless following holds true, if(m==n)&&(n!=p)?
15. Predict the output of the following code snippet: (a) 'm' and 'n' are equal (b) 'n' and 'p' are equal
int a = 1; int b = 2; if (a == b) (c) 'm' and 'p' are equal (d) none
System.out.println ("Both values are equal"); else 26. A compound statement can be stated as
(a) =in.nextInt(); q=in.nextInt(); (b) m=++a; n=--b; 33. Read the following text, and choose the correct
(c) if(a>b) {a++;b--;} (d) none answer:
27. if((p>q)&&(q>r)) then In Java, the "switch" statement is used for multi-way
(a) q is the smallest number branching based on the value of an expression.
(b) q is the greatest number
Which of the following is true about the "switch"
(c) p is the greatest number
statement in Java?
(d) none
(where p, q and r are three integer numbers) (a) It can only be used with integer data types.
(b) It can be used with both integer and floating-point
28. if(a<b) c=a; else c=b; data types.
It can be written as: (c) It can be used only with wrapper data types.
(a) c= (b<a)?a:b; (b) c= (a!=b)?a:b; (d) It can only be used with boolean data types.
(c) c= (a<b)?b:a; (d) none
29. if(a<b && a<c)
(a) a is the greatest number
(b) a is the smallest number Iterative statement
(c) b is the greatest number
(d) none 1. How many times will the following loop execute?
(where a, b and c are three integer numbers) int i = 0;
while (i < 5) {
30. Assertion (A): The `switch` statement in Java can be used System.out.println(i);
with `String` variables.
i++;
Reason (R): The `switch` statement can only be used with
}
`int`, `char`, and `enum` types.
(a) Both Assertion and Reason are correct, and the Reason is (a) 4 times (b) 5 times
the correct explanation for the Assertion. (c) 6 times (d) Infinite loop
(b) Both Assertion and Reason are correct, but the Reason is
not the correct explanation for the Assertion. 2. Which of the following statements about the `while`
(c) The Assertion is correct, but the Reason is incorrect. loop is false?
(d) The Assertion is incorrect, but the Reason is correct. (a) The `while` loop will execute as long as the
Explanation: In Java, the `switch` statement can indeed be condition is true.
used with `String` variables (since Java 7). However, the
(b) The `while` loop must have a condition.
Reason is incorrect because the `switch` statement is not
(c) The `while` loop always executes at least once.
limited to `int`, `char`, and `enum` types
(d) The `while` loop can be terminated with a `break`
.
31. Name the following picture depicts statement.
3. What will be the output of this code?
int i = 0;
do {
System.out.println(i);
i++;
break;
} while (i < 3);
(a) polymorphism (b) if else (a) 0 1 2 (b) 0
(c) switch (d) both b and c (c) 1 (d) error
32. Name the following picture depicts 4. Which loop is guaranteed to execute at least once?
(a) `for` loop (b) `while` loop
(c) `do-while` loop (d) None
5. What is the output of the following code?
for (int i = 0; i < 3; ) {
System.out.println(i);
}
(a) loop (b) abstraction (a) 0 1 2 (b) 0 1 2 3
(c) swtich (d) if else (c) none (d) error
6. What will the following code output? i++;
int i = 0; }
for (; i < 3;) { (a) 0 1 2 (b) 0 1 2 3
System.out.println(i); (c) 1 2 3 4 (d) 0 1 2 3 4
i++; 13. What is the purpose of the `break` statement in a
} loop?
(a) 1 2 3 (b) 0 1 2 3 (a) To terminate the loop immediately
(c) 0 1 2 (d) Error (b) To skip the current iteration
7. What is the result of the following code? (c) To restart the loop
int i = 0; (d) To continue to the next iteration
for (i = 0; i < 5; i += 2) { 14. What is the purpose of the `continue` statement in
System.out.println(i); a loop?
} (a) To terminate the loop immediately
(a) 0 2 (b) 0 2 4 (b) To skip the current iteration and proceed with the
(c) 1 3 5 (d) 0 1 2 3 4 next iteration
8. Which of the following statements is true about the (c) To restart the loop
`for` loop? (d) To exit the loop
(a) The `for` loop requires an initialization, a 15. What will be the output of the following code?
condition, and an increment/decrement statement. for (int i = 1; i < 4; i++) {
(b) The `for` loop only needs a condition to execute. System.out.print(++i + " ");
(c) The `for` loop can execute without an initialization. }
(d) The `for` loop cannot be used without a condition. (a) 1 2 3 (b) 1 2 3 4
9. What will be the output of this code? (c) 1 3 (d) 2 4
int i = 1;
while (i++ <= 5); 16. Which statement is true about the `do-while` loop?
System.out.print(i + " "); (a) The condition is evaluated after the loop body
(a) 1 2 3 4 5 (b) 6 executes.
(c) 5 (d) none (b) The condition is evaluated before the loop body
10. Which of the following loops is best for iterating a executes.
known number of times? (c) The `do-while` loop will not execute if the
(a) `for` loop (b) `while` loop condition is false
(c) `do-while` loop (d) None (d) none
11. What will be the output of the following code? 17. class Pattern
int x = 0; {
while (x < 5) { public static void main()
x++; {
if (x == 3) { Integer a=0;
continue; int i=1;
} while(i<=2)
System.out.print(x + " "); {
} a=a*10+1;
(a) 1 2 (b) 1 2 4 System.out.println(a);
(c) 1 2 4 5 (d) 1 2 4 5 i++;
12. What is the result of the following code snippet? }
int i = 0; }
while (i < 5) { }
System.out.print(i + " "); }
if (i == 2) { What will be the output of the code?
break; a. 0
} 11
else b. 1
11
c. 1 Explanation: The `break` statement in Java exits the
10 loop entirely and does not continue with the next
d. error iteration. The Reason is correct because it accurately
18. Which of the following is an example of infinite describes the behavior of the `break` statement.
loop? 25. Name the flowing picture depicts:
a. for( ; ; ) b. while(true)
c. while() d. none
19. A loop without body is called
a. Null loop b. Empty loop
c. Both a and b d. None
20. int i ,j=0 sum=0;
for( i=1;i<=5;i++)
for( j = 2; j<=5; j++)
break;
sum =sum + j; (a) conditional construct (b) iterative construct
Which of the following is the final value of sum? (c) jumping construct (d) all of them
a. 1 b. 2 26. Name the flowing picture depicts:
c. 50 d. 60 (a) if else (b) switch
21. int i ,j=0 sum=0; (c) Loop (d) all of them
for( i=1;i<=5;i++);
for( j = 2; j<=5; j++)
sum =sum + j;
a. 60 b. 90
c. 70 d. 14
22. Give the output of following code:
int i;
for(i=0;i<2;i++);
System.out.println(++i);
a. 2 b. 3 27. Give the output of following code and mention how
c. 1 d. Runtime Error many times the loop will execute?
23. Give the output of following code: int i;
int i=0; for( i=5 ; i>=1 ;i--)
for(System.out.println(++i);i<2;i++); {
a. 0 b. 1 if(i%2 ==1)
c. Syntax Error d. Runtime Error continue;
24. Assertion (A): The `break` statement in Java exits System.out.print( i+ “ ”);
the current loop and continues with the next iteration }
of the loop. (a) 2 4 & 5 times (b) 4 2 & 5 times
Reason (R): The `break` statement is used to exit the (c) 4 2 & 4 times (d) 4 2 & 6 times
loop and transfer control to the statement immediately 28. Give the output of the following program segment
following the loop. and also mention the number of times the loop is
executed:
(a) Both Assertion and Reason are correct, and the int a, b;
Reason is the correct explanation for the Assertion. for (a = 6, b = 4; a <= 24; a = a + 6)
(b) Both Assertion and Reason are correct, but the {
Reason is not the correct explanation for the Assertion. if (a%b ==0)
(c) The Assertion is correct, but the Reason is break;
incorrect. }
(d) The Assertion is incorrect, but the Reason is System.out.println(a);
correct. (a) 12 & 2 times (b) 12 & 3 times
(c) 14 & 2 times (d) 10 & 2 times
29. How many times does the inner loop execute and 33. Assertion: The "break" statement in Java is used to
number of time WIN is obtained as output? terminate the current iteration of a loop.
for(int i=3;i<=4;i++ ) Reason: It allows the program to exit the loop entirely.
{ (a) Both the assertion and reason are correct, and the
for(int j=2;j<i; j++ ) reason is a correct explanation of the assertion.
{ (b) Both the assertion and reason are correct, but the
System.out.print(""); reason is NOT a correct explanation of the assertion.
} (c) The assertion is correct, but the reason is incorrect.
System.out.println("WIN"); (d) The assertion is incorrect.
}
(a) 2 & 2 times (b) 3 & 3 times
(c) 3 & 2 times (d) 3 & 2 times
30. How many time the loop is executed and what is the
output?
int x=97;
do{
char ch = (char) x;
System.out.print (ch+“,”);
if(x%10==0)
break;
x++;
} while(x<=110);
(a) a,b,c,d & 4 times (b) a,b,c,d,e,f & 6 times
(c) a,b,c,d, & 4 times (d) a,b,c,d,e, & 4 times
31. The output of the given code is :
int i=5;
for(;i<=125;i*=5)
System.out.print (i+“”);
System.out.println(“,”+i);
a) Error
b) It will print all numbers from 5 till 125 with
difference of 5 each time
c) 525125625,
d)525125
625,
32. Assertion: There are three main types of loops in
Java: for, while, and do-while.
Reason : Each type of loop has its own use case. The for
loop is useful when you know the number of iterations
in advance. The while loop is suitable for situations
where the condition for termination is known, but the
number of iterations may vary. The do-while loop
ensures that the code block is executed at least once,
regardless of the condition.
(a) Both Assertion (A) and Reason (R) are true and
Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and
Reason (R) is not a correct explanation of Assertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true

You might also like