0% found this document useful (0 votes)
24 views24 pages

Class 10 ICSE Practice Paper 2

This document contains a practice paper for Class 10 students featuring multiple-choice questions (MCQs) related to Java programming concepts. The questions cover various topics including output predictions, operator precedence, control statements, and data types. Each question is followed by multiple answer options, allowing students to test their knowledge and understanding of Java.

Uploaded by

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

Class 10 ICSE Practice Paper 2

This document contains a practice paper for Class 10 students featuring multiple-choice questions (MCQs) related to Java programming concepts. The questions cover various topics including output predictions, operator precedence, control statements, and data types. Each question is followed by multiple answer options, allowing students to test their knowledge and understanding of Java.

Uploaded by

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

CLASS 10 MCQ PRACTICE PAPER - 2

1) System.out.println(“a”+0+’A’);
a) a0A b) a065c) a65 d) a4564

2) System.out.println(‘A’+’1’+“B”);
a) A1B b) A49B c) 651B d) 114B

3) System.out.print(‘A’+’1’);
a) A1 b) 651 c) 6549 d) 114

4) System.out.println(‘B’+9+’z’);
a) B9z b) 669122 c) 245 d) 197

5) System.out.println(“ADD”+(‘A’+’B’));
ADDAB b) ADD6566 c) ADD131 d) ADDA+B

6) String n=”210”; n=n+’A’;


System.out.println(n);
System.out.println(Integer.parseInt(n)+20));
a) 210A b) 210 c) 21065 d) 210A
A230 230 Error
21020

7) String n=”210”, m=”302”;


int n = Integer.parseInt(n)+Integer.parseInt(m); System.out.println(n);
a) 210302 b) 512 c) 210+302 d) Error

8) double d=35.45, e=25.55;


System.out.println(String.valueOf(d)+String.valueOf(e));
a) 35.4525.55 b) 61.00 c) 65.45+25.55 d) Error

9) double d=45.35, e=15.55; System.out.println(Double.toString(d)+Double.toString(e));


a) 45.3515.55 b) 60.90 c) 45.35+15.55 d) Error

10) int a=100,b=200;


System.out.println("ADD"+a+b);
a)ADD100200 b) ADD300 c) ADD100+200 d) Error

11) int a=400,b=500;


System.out.println("ADD"+(a+b));
a)ADD400500 b) ADD400+500 c) ADD900 d) Error

12) int a=600,b=500;


System.out.println("ADD"+a-b);
a)ADD600-500 b) ADD100 c) ADD600500 d) Error

13) int a=600,b=500;


System.out.println("ADD"+(a-b));
a)ADD600-500 b) ADD100 c) ADD600500 d) Error
14) Which one of the types cannot be used as a switch variable?
a) char b) byte c) int d) float

15) Which operation will be performed first in the given expression: ++x / b+c * d % e
a) ++ b) + c) * d) %

16) Arrange the following in ascending order of precedence: + , != , || , % , ++


a) ++ , % , + , !=, || b) ++ , % , + , ||, !=, c) % ,++ , + , !=, || d) ++ ,, + , %, !=, ||

17) In the following program segment what are x nd y?


void main()
{
int x=10,
y=15;
display(x,
y);
}
a) actual parameter b) formal parameter c) local parameter d) none of them

18) An identifier in Java can begin with:


a) digit b) space c) letter d) any symbol

19) Pick the odd one out:


a) method b) block of code in {} c) function d) package

20) The method that does not modify its parameters:


a) virtual function b) pure function c) impure function d) accessor function

21) Which of the methods will be called by reference?


a) void Sample(int a) b) void Sample(int a[]) c) void Sample(char d) d) void Sample(float f)

22) Given the following method prototype: int Change(int p, int


q);
The statement to call the method is:
a) Change(10,20); b) s = Change(10,20); c) Change(4.5,5.6); d)s=Change(4.5,5.5);

23) Function signature means:


a) list of arguments b) return type c) name of method d) return value

24) The prototype of a function Show(), that returns a float and takes two integer arguments is:
a) void Show(int a,int b) b) float Show(int a, int b)
c) float Show(int a) d) static Show(int a,int b)

25) Fill in the blanks to import all the classes of the


package “Education”, import Education. ;
a. # b) all c) * d) **

26) What is the output produced by the following lines


of program code?
char x,z;
int y; x = 'A';
y = ++x;
z = (char)y; System.out.println(x+"\
t"+y+"\t"+z);
a) B 66 B b) A 66 B c) A 65 B d) Error

27) Write the output of the following statement:


System.out.println("A picture is worth \t \"A thousand words.\" ");
a. A picture is worth A thousand words.
b. A picture is worth “A thousand words.”
c. A picture is worth “A thousand words.”
d. “A picture is worth “A thousand words.””
28) for(a=0;a<5;a++)
System.out.print(a*a);
System.out.print(a);
a) 0 1 4 9 16 0 1 2 3 4 b) 0 0 1 1 4 2 9 3 16 4 c) 0 1 4 9 16 6 d) 0 1 4 9 16 5

29) if ( n > m)
System.out.print(“GOOD”);
System.out.print(“LUCK”);
else
System.out.print(“DONE”);
What will be the output if n=6 and m=4?
a)GOOD b) GOODLUCK c) DONE d) Error

30) System.out.println(Math.ceil(-9.4)+Math.sqrt(9.0));
a) 6.0 b) -6.0 c) -5.0 d) 5.0

31) Which of the following statements is not true about a static method?
a. It can be invoked without creating an object.
b. It can be called by a non-static method.
c. It can access instance variables directly.
d. It can access static variables directly.

32) To successfully overload a method in Java, the return types must be .


a. Same
b. Different
c. Same but using superclass or subclass types also work
d. None

33) The placement of a constructor inside a class should be .


a. Always at the beginning of class
b. Always at the end of class
c. Anywhere in the class
d. None

34) The condition of an IF statement evaluates to boolean only if the expression contains?
a. logical operators
b. relational operators
c. boolean operands
d. All

35) If the condition of an IF-statement is false, which is true below.


a. IF block is executed.
b. ELSE block is executed.
c. Both IF and ELSE blocks are skipped.
d. Both IF and ELSE blocks are executed.

36) An IF-ELSE statement is better than a SWITCH statement in which scenario below?
a. Checking for More-than condition
b. Checking for Less-than condition
c. Checking for Ranges
d. all

37) What is the output of Java program with


SWITCH?
int num=20;
switch(num)
{
case 10: System.out.println("TEN"); break;
case 20: System.out.println("TWENTY"); break;
case 30: System.out.println("THIRTY");
}
a. TEN
b. TWENTY
c. THIRTY
d. TEN TWENTY
38) What is the output of Java program below? int num=40;
switch(num)
{
case 5: System.out.println("FIVE"); break;
case 35+5: System.out.println("FORTY"); break;
case 20+30: System.out.println("FIFTY");
}
a. FIVE
b. FORTY
c. FIFTY
d. Compiler error

39) What is the output of the below Java program with a SWITCH
statement? int points=6;
switch(points)
{
case 6: ;
case 7: System.out.println("PASS");break;
case 8: ;
case 9: System.out.println("Excellent");break;
case 10: System.out.println("Outstanding");
break; default: System.out.println("FAIL");
}
a. PASS
b. Excellent
c. Outstanding
d. FAIL

40) Choose the correct statement about Java SWITCH statements.


a. A SWITCH can contain another SWITCH statement.
b. Switch case statements are allowed inside IF-ELSE ladders.
c. Switch statements are allowed inside Loops like for, while and do while.
d. All

41) What is the output of the below Java program? int


hours = 10;
switch(hours)
{
case 10: System.out.println("TEN");break;
case 10: System.out.println("TEN AGAIN"); break;
default: System.out.println("TEN AS USUAL");
}
a. TEN
b. TEN AGAIN
c. TEN AS USUAL
d. Compiler error

42) A java Ternary operator has priority less than .


a. Relational operators
b. Arithmetic operators
c. Logical and bitwise operators
d. All

43) What is the output of the Java code snippet with Ternary operator?
int num = false?10:20;
System.out.println(num);
a) 10
b) 20
c) 0
d) Compiler error

44) What are the types of data that can be used along with Relational operators in Java?
a. char, boolean, Object
b. byte, short, int, long
c. float, double
d. All the above

45) Choose the Conditional operators of Java listed below.


a) >, >=
b) <, <=
c) ==, !=
d) All the above

46) What is the output of Java code snippet?


int a=5, b=10;
if(++b>10||a++==5)
{
System.out.println("PIZZA="+a);
}
else
{
System.out.println("BURGER="+a);
}
a. PIZZA=5
b. PIZZA=6
c. BURGER=5
d. BURGER=6

47) In java control statements break, continue, return, try-catch-finally and assert belongs to?
A. Selection statements
B. Loop Statements
C. Transfer statements
D. Pause Statement
Answer: _______________

48) Which provides runtime environment for java byte code to be executed?
A. JDK
B. JVM
C. JRE
D. JAVAC
Answer: _______________

49) What is byte code in Java?


A. Code generated by a Java compiler
B. Code generated by a Java Virtual Machine
C. Name of Java source code file
D. Block of code written inside a class
Answer: _______________

50) Which of the following are not Java keywords?


A. double
B. switch
C. then
D. instanceof
Answer: _______________

51) Which of these have highest precedence?


A. ()
B. ++
C. *
D. &&
Answer: _______________

52) Data type long literals are appended by _____


A. Uppercase L
B. Lowercase l
C. Long
D. Both A and B
Answer: _______________
53) Which variables are created when an object is created with the use of the keyword 'new' and
destroyed when the object is destroyed?
A. Local variables
B. Instance variables
C. Class Variables
D. Static variables
Answer: _______________

54) Which one is a template for creating different objects ?


A. An Array
B. A class
C. Interface
D. Method
Answer: _______________

55) Which symbol is used to contain the values of automatically initialized arrays?
A. Brackets
B. Braces
C. Parentheses
D. Comma
Answer: _______________

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

57) Which of these is returned by Greater Than, Less Than and Equal To (i.e Relational) operator ?
A. Float
B. Integer
C. Boolean
D. Double
Answer: _______________

58) Which statement transfer execution to different parts of your code based on the value of an expression?
A. If
B. Switch
C. Nested-if
D. if-else-if
Answer: _______________

59) Modulus operator (%) can be applied to which of these?


A. Integers
B. Floating - point numbers
C. Both A and B
D. None of These
Answer: _______________

60) Division operator has ____ precedence over multiplication operator


A. Highest
B. Least
C. Equal
D. None of These
Answer: _______________

61) What is the full form of JVM ?


A. Java Very Large Machine
B. Java Verified Machine
C. Java Very Small Machine
D. Java Virtual Machine
Answer: _______________
62) In Java code, the line that begins with /* and ends with */ is known as?
A. Multiline comment
B. Single line comment
C. Both A & B
D. None of these
Answer: _______________

63) Write the output:


char ch = 'F';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);
A. 107 F
B. K F
C. 75 F
D. None of these
Answer: _______________

64) Write the output of the following statement:


System.out.println("A picture is worth \t \"A thousand words.\" ");
A. A picture is worth A thousand words.
B. A picture is worth “A thousand words.”
C. A picture is worth “A thousand words.”
D. Error
Answer: _______________

65) It is compulsory to return a value from a function.


A. True
B. False
Answer: _______________

66) A function in Java can be written


A. Inside a class
B. Outside a class
C. Inside a main() function
D. None of these
Answer: _______________

67) An overloaded function is


A. A function with same name but different return types
B. A function with same name but different number of parameters
C. A function with same name but different type of parameters
D. Both B and C
Answer: _______________

68) Which of the following is a valid declaration of a char?


char ch = '\utea';
char ca = 'tea';
char cr = \u0223;
char cc = '\itea';
Answer: _______________

69) Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
24
23
20
25
Answer: _______________

70) Which of the following for loop declaration is not valid?


for ( int i = 99; i >= 0; i / 9 )
for ( int i = 7; i <= 77; i += 7 )
for ( int i = 20; i >= 2; - -i )
for ( int i = 2; i <= 20; i = 2* i )
Answer: _______________

71) Given that Student is a class, how many reference variables and objects are created by the
following code?
Student studentName, studentId;
studentName = new Student();
Student stud_class = new Student();
Three reference variables and two objects are created.
Two reference variables and two objects are created.
One reference variable and two objects are created.
Three reference variables and three objects are created.
Answer: _______________

72) Which statement is true about Java?


Java is a sequence-dependent programming language
Java is a code dependent programming language
Java is a platform-dependent programming language
Java is a platform independent programming language
Answer: _______________

73) What will be the output of the following Java program?


class evaluate
{
public static void main(String args[])
{
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
n = arr[arr[n] / 2];
System.out.println(arr[n] / 2);
}
}
2
1
4
0
Answer: _______________

74) What is the extension of compiled java classes?


.txt
.js
.class
.java
Answer: _______________

75) What will be the output of the following Java code?


double x = 3.14;
int y = (int) Math.ceil(x);
System.out.print(y);
3
0
4
3.0
Answer: _______________

76) Find the output of the following


int a[ ]={3,2,15,16,18};
int i=a[1];
int n=a[2]++;
int m=a[i++];
System.out.println(i+”\t “+n+”\t “+m);
2 15 16
2 16 15
3 15 16
3 16 15
Answer: _______________

77) Read the following program and answer the questions given below
class Method
{
double compute(int a, int b)
{
return (a+b)/2.0;
}
static void main()
{
Method ob=new Method():
_______A______;
}
}
Which of the following statements will correctly invoke the method compute() in line ‘A’;
System.out.println(ob.compute(15));
ob.compute(15,19);
ob.compute();
System.out.println(ob.compute(15,19));
Answer: _______________

78) Which of the following statements is not the correct way to declare overloaded methods.
void area(int x)
void area(float x)
int area(int x)
void area(double x)
Answer: _______________

79) Every loop in Java has a condition that should be ___ in order to proceed for execution.
FALSE
TRUE
Answer: _______________

80) A WHILE loop in Java executes the statements at least once even the condition is not satisfied.
a) FALSE
b) TRUE
Answer: _______________

81) A FOR loop in Java generally contains a Loop-Counter variable.


(a) FALSE
(b) TRUE
Answer: _______________

82) What is the output of the below Java program with WHILE, BREAK and CONTINUE?
int cnt=0;
while(true)
{
if(cnt > 4)
break;
if(cnt==0)
{
cnt++;
continue;
}
System.out.print(cnt + ",");
cnt++;
}
a) 0,1,2,3,4,
b) 1,2,3,4,
c) 1,2,3,4
d) Compiler error
Answer: _______________

83) What is the main difference between a WHILE and a DO-WHILE loop in Java?
a) WHILE loop executes the statements inside of it at least once even if the condition is false.
b) DO-WHILE loop executes the statements inside of it at least once even if the condition is false.
c) WHILE loop is fast.
d) DO-WHILE loop is fast.
Answer: _______________

84) What is the output of the below Java code?


int score=1;
for(; true; score++)
{
System.out.print(score +",");
if(score > 3)
break;
}
a. 1,2,3,
b. 1,2,3
c. 1,2,3,4,
d. 1,2,3,4
Answer: _______________

85) Which of the following are access modifiers in Java?


a. public
b. private
c. protected
d. All the above

86) What is an access modifier in Java?


a. An access modifier controls the visibility of variables, constants and methods of a class
b. An access modifier can hide or show a variable or method to outside classes.
c. Access modifiers help in implementing the Encapsulation feature of OOPs.
d. All the above

87) Which is the keyword used to specify the DEFAULT access modifier in java?
a. default
b. bydefault
c. normal
d. There is no keyword

88) Which is the less restrictive access modifier in Java?


a. public
b. private
c. protected
d. default

89) Which is the most restrictive access modifier in Java?


a. public
b. private
c. protected
d. default

90) Is it possible to combine more than one access modifier in Java?


a. No
b. Yes
91) Which of these access specifiers must be used for main() method?
a) private
b) public
c) protected
d) none of the mentioned

92) Which of these is used to access a member of class before object of that class is created?
a) public
b) private
c) static
d) protected
93) Which of these is used as a 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

94) What is the process by which we can control what parts of a program can access the members of
a class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion

95) Which of the following statements are incorrect?


a) public members of class can be accessed by any code in the program
b) private members of class can only be accessed by other members of the class
c) private members of class can be inherited by a subclass, and become protected members in
subclass
d) protected members of a class can be inherited by a subclass, and become private members of
the subclass
96) Which of these access specifier must be used so that it can be inherited by another subclass?
a) public
b) private
c) protected
d) none of the mentioned

97) The private member of a class can be accessible


a) Within the class in which it is declared
b) Within all the sub-classes of its class in any package where this class is visible
c) Within all the classes in the package containing its class
d) None of the above

98) The protected member of a class can be accessible


a) Within all the sub-classes in any package.
b) Within all the classes in the package containing its class
c) Within all the classes in any other package
d) both a and b

99) The public member of a class can be accessible


a) Within the class in which it is declared
b) Within the package containing its class
c) Other packages where this class is visible
d) All of the above

100) Can you access a default member of a class from a class outside the current package?
a. No
b. Yes

101) Choose the correct statement about access modifiers in Java.


a. public, protected and default variables and methods can be accessed outside the
package somehow.
b. public and protected variables and methods can be accessed outside the package somehow.
c. Only public variables and methods can be accessed outside the package somehow.
d. None of the above
102) To access a protected variable or method of a Class outside the package, you need to.
a. Create an instance and call the protected variable or method
b. Create a Subclass and call the protected variable or method
c. A and B
d. None of the above

103) Choose the correct Java code snippet with access modifiers below?
a. class ABC { }
b. private protected class ABC { }
c. protected public class ABC { }
d. protected private class ABC { }

104) Visible in the classes and subclasses in the same package and subclasses in other packages.
a. private
b. public
c. protected
d. default

105) The __ access specifier used in a class cannot be accessed by subclass in the same package.
a. private
b. public
c. protected
d. default

106) Which among the following can restrict class members to get inherited?
a) Private
b) Protected
c) Public
d) All three

107) Which among the following allows class members to get inherited?
a) Private
b) Protected
c) Public
d) All three

108) Which access specifier is used when no access specifier is used with a member of class (java)?
a) Private
b) Default
c) Protected
d) Public

109) The default constructor is used for


a) Calling default methods
b) Intializing default values to objects
c) Deferencing default objects
d) All of above
110) In Java, a constructor with no parameters or no arguments is called …….. Constructor.
a) Default constructor
b) User-defined constructor
c) Static construction
d) Custom construction
111) Default constructor requires how many parameters?
a) 3
b) 2
c) 0
d) 1
112) Which principle in Object-Oriented programming is followed during Java constructor
overloading
a) Polymorphism
b) Encapsulation
c) Inheritance
d) None of the above
113) How many objects of the class will be created if the default constructor is not defined ?
a) Compiler provide its default constructor to build the object.
b) The compiler will generate the error
c) Error will occur at run-time
d) All of the above
114) Java constructor is like a method without …………..
a) Argument list
b) Return type
c) Statements
d) None
115) The placement of a constructor inside a class should be ……………
a) Always at the beginning of class
b) Always at the end of class
c) Anywhere in the class
d) None
116) If constructor has a return type then .
a) Runtime error
b) Compilation error
c) Compilation and runs successfully
d) None of the above
117) A Constructor without any Parameters is called ……………
a) Static
b) Custom
c) Dynamic
d) Default
118) The name of a constructor and the name of a class are …………
a) Same
b) Different
c) Default
d) None of these
119) What is the value of Math.pow(a[3],a[0]) in {4, 5, 2, 3,6,1}?
a) 16
b) 81
c) 32
d) 27
120) Array in java is ___.
a) Finite collection of similar elements
b) Finite collection of elements of different types
c) The data type of consisting of characters
d) None of these
121) Given that Student is a class, how many reference variables and objects are created by the
following code?
Student studentName, studentId;
studentName = new Student();
Student stud_class = new Student();
a. Three reference variables and two objects are created.
b. Two reference variables and two objects are created.
c. One reference variable and two objects are created.
d. Three reference variables and three objects are created.
122) What will be the output of the following Java program?
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
n = arr[arr[n] / 2];
System.out.println(arr[n] / 2);
a) 2
b) 1
c) 4
d) 0
123) The number of bytes occupied by array char ch[ ]={‘A’ , ‘E’ , ‘I’ , ‘O’ , ‘U’};
a) 15
b) 20
c) 10
d) 5
124) 17. The method with the same name as of the class and which does not have a return data
type is called as
a) Constructor
b) Function
c) Method
d) Package

125) Find the output:


int a[ ]={5,3,1,7,2};
a. int x=a[4];
b. int y = a[x];
c. int z = a[y];
d. System.out.println(x+" "+y+" "+z);

126) int a[ ]={5,3,2,1,4};


a. int x=a[0];
b. int a[x]=a[4];
c. int z = a[x]*a[4];
d. System.out.println(z);

127) int b[] = {10,14,12,10,12,8,16,18,13};


a. int q = 4;
b. int p = b[b[q]/2];
c. System.out.println(p) ;

128) int x[]={5,3,5,6,2};


a. x[0]=(int)Math.pow(x[2],x[1]);
b. int y=(x[0] + x[4])/x[1];
c. System.out.println(y);

Java Virtual Machine (JVM) is an:


129) (a) Interpreter (b) Compiler (c) Machine Code (d) Byte Code
130) 2. Which of the following is non-primitive data type?
131) (a) char (b) long (c) String (d) short
132) 3. The statement n++ is equivalent to:
133) (a) ++n (b) n=n+1 (c) n+1 (d) none
134) 4. The java compiler translates java source programs to:
135) (a) Machine Language (b) Bytecode (c) System Language (d) Native Code
136) 5. The size of “int” data type is:
137) (a) 8 bits (b) 16 bits (c) 32 bits (d) 64 bits
138) 6. What is the return type of a constructor?
139) (a) void (b) Boolean (c) int (d) None of the above
140) 7. What is the result produced after the following statements are executed:
141) int a = 2,b, c;
a = a+4;
b = 3*a;
c = a-b;
System.out.println(2+c+c);
142) (a) 2cc (b) -22 (c) 200 (d) 22
143) 8. a[16] is the _________ element of the array declared as char a[20];
144) (a) 16th (b) 15th (c) 17th (d) None of the above
145) 9. The access specifier, return type and function signature together is known as: Function
________
146) (a) Prototype (b) Signature (c) Definition (d) Call
147) 10. The default delimiter in Scanner class is:
148) (a) Tab character (b) Blank Character (c) All of the above (d) None of the
above
149) 11. With respect to the input “This is a cat”, what will be the values in ‘x’ and ‘y’ after the
execution of the following statements:
String x = sc.next();
String y = sc.nextLine();
150) (a) x=This , y=is (b) x=This , y=is a cat (c) x=This is a , y=cat (d) None of the above
151) 12. What is the return type of the following method: x.equals(y)
152) (a) yes or no (b) right or wrong (c) All of the above (d) None of the above
153) 13. Two Arithmetic expressions can be joined with if statement, using:
154) (a) Logical operator (b) Null operator (c) Arithmetic operator (d) Ternary
operator
155) 14. Which of the following is not a keyword?
156) (a) false (b) void (c) while (d) main
157) 15. Which of the following statement is an invalid array declaration?
158) (a) int [ ][ ]n; (b) int n[ ]; (c) int n[4]; (d) int n[ ][ ];
159) 16. More than one java statements together is called block/compound statements. They are
enclosed in:
160) (a) Parenthesis (b) Braces (c) Square brackets (d) /* and */
161) 17. An array is created as follows:
boolean b[]=new boolean[10];
How many bits will be used for the array?
162) (a) 1 (b) 8 (c) 16 (d) 10
163) 18. Character function which checks whether a character is a digit or not:
164) (a) isLetterOrDigit() (b) isDigit() (c) Both a and b (d) None of
the above
165) 19. A class is a ______________ data type.
166) (a) Primitive (b) Composite (c) user-defined (d) both b and
c
167) 20. The property of OOP which is implemented through the concept of function
overloading
168) (a) Encapsulation (b) Abstraction (c) Polymorphism (d)
Modularity
169) 21. The Java compiler translates Java programs to intermediate level language called:
170) (a) Machine Language (b) Byte Code (c) System Language (d) Native
Executable Code
171) 22. double c , x = 5, y=10;
int z=51;
c = x * y + z/2.5;
What is the value now stored in c?
172) (a) 70 (b) 40.4 (c) 70.4 (d) 152
173) 23. Java Virtual Machine (JVM) is a:
174) (a) Interpreter (b) Compiler (c) Machine Code (d) Byte Code
175) 24. If a function returns a value, the return type of the function will not be:
176) (a) int (b) float (c) void (d) None of the
above

177) 25. Which of the following can be used when you know the number of times we
have to perform a task:
178) (a) for loop (b) while loop (c) do-while loop (d) All of the above
179) 26. 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

180) 27. Which of these coding types is used for data type characters in Java?
a) ASCII b) ISO-LATIN-1 c) UNICODE d) None of the
mentioned

181) 28. Which of these values can a boolean variable contain?


a) True & False b) 0 & 1 c) Any integer value. d) Both a & b

182) 29. Which of these occupy first 0 to 127 in Unicode character set used for characters
in Java?
a) ASCII b) ISO-LATIN-1 c) None of the mentioned d) Both a
&b

183) 30. Which one is a valid declaration of a boolean?


a) boolean b1 = 1; b) boolean b2 = ‘false’; c) boolean b3 = false; d) boolean
b4 = ‘true’

184) 31. What is the stored in the object obj in following lines of code? box obj;
a) Memory address of allocated memory of object.
185) b) NULL
186) c) Any arbitrary pointer
a) Garbage

187) 32. Which of these keywords is used to make a class?


a) class b) struct c) int d) None of the
mentioned

188) 33. Which of the following is a valid declaration of an object of class Box?
a) Box obj = new Box(); b) Box obj = new Box;
189) c) obj = new Box(); d) new Box obj;

190) 34. Which of these operators is used to allocate memory for an object?
a) malloc b) alloc c) new d) give

191) 35. Which of these statement is incorrect?


a) Every class must contain a main() method.
b) Applets do not require a main() method at all.
c) There can be only one main() method in a program.
192) d) main() method must be made public.

193) 36. Which of these have highest precedence?


a) () b) ++ c) * d) >>

194) 37. What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ? expression2 : expression3
a) Integer b) Floating – point numbers c) Boolean d) None of the
mentioned

195) 38. What is the value stored in x in following lines of code?


int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
a) 0 b) 1 c) 9 d) 8

196) 39. What is the order of precedence (highest to lowest) of following operators?
1. &
2. ^
3. ?:
a) 1 -> 2 -> 3
b) 2 -> 1 -> 3
c) 3 -> 2 -> 1
d) 2 -> 3 -> 1

197) 40. Which of these statements are incorrect?


a) Equal to operator has least precedence.
b) Brackets () have highest precedence.
c) Division operator, /, has higher precedence than multiplication operator.
d) Addition operator, +, and subtraction operator have equal precedence.
198) What is the output of this program?
199) class main_class {
200) public static void main(String args[])
201) {
202) int x = 9;
203) if (x == 9) {
a. int x = 8;
b. System.out.println(x);
204) }
205) }
206) }
a) 9
b) 8
c) Compilation error
d) Runtime error

207) Which of the following statements is correct?


a) Public method is accessible to all other classes in the hierarchy
b) Public method is accessible only to subclasses of its parent class
c) Public method can only be called by object of its class.
d) Public method can be accessed by calling object of the public class.

208) What is the output of this program?


209) class array_output {
210) public static void main(String args[])
211) {
212) char array_variable [] = new char[10];
a. for (int i = 0; i < 10; ++i) {
b. array_variable[i] = 'i';
c. System.out.print(array_variable[i] + "" );
d. i++;
213) }
214) }
215) }
216) a) i i i i I b) 0 1 2 3 4 c) i j k l m d) None of the
mentioned

217) What is the output of this program?


218) class mainclass {
219) public static void main(String args[])
220) {
221) char a = 'A';
222) a++;
a. System.out.print((int)a);
223) }
224) }
225) a) 66 b) 67 c) 65 d) 64
226)
What is the output of this program?
227) class mainclass {
228) public static void main(String args[])
229) {
230) boolean var1 = true;
a. boolean var2 = false;
b. if (var1)
a) System.out.println(var1);
c. else
a) System.out.println(var2);
231) }
232) }
233) a) 0 b) 1 c) true d) false

234) What is the output of this program?


235) class booloperators {
236) public static void main(String args[])
237) {
238) boolean var1 = true;
a. boolean var2 = false;
b. System.out.println((var2 & var2));
239) }
240) }
241) a) 0 b) 1 c) true d) false

242) What is the output of this program?


243) class asciicodes {
244) public static void main(String args[])
245) {
246) char var1 = 'A';
a. char var2 = 'a';
b. System.out.println((int)var1 + " " + (int)var2);
247) }
248) }
249) a) 162 b) 65 97 c) 67 95 d) 66 98
250) Given the following programming code:
251) public boolean x(int a, int b)
{
boolean c = true;
while(a>1 && b>1)
{
if(a>b)
a-=b;
else
b-=a;
}
if(a ==1 || b == 1)
c = false;
return c;
}
(a) What will be the output of the above program code for,
252) (i) x (28, 29)
(ii) x (27, 39)
253) (b) What is the above method calculating? (Answer should be in one line)
254)
What will be the output of the below code when n=145
255) int number(int n)
{
int s=0;
while(n>0)
{
s=s+n%10;
n/=10;
}
return n;
}
256) Give the output of the below code:
257) public static void main()
{
String s1=”Java For”, s2=”School Students”;
System.out.println(“L”+s1.substring(1,4));
System.out.println(s2.indexOf(s1.charAt(6)));
System.out.println(s1.concat(s2));
System.out.println(s1.compareTo(s2));
System.out.println(s2.equals(s1));
}
258) Give the output of the below code:
259) public static void main()
{
int c=900,n=2000;
int x=0,y=0;
x=n+(c>2550?1350:1500);
y=n+c>2550?1350:1500;
System.out.println(“x = “+x);
System.out.println(“y = “+y);
}

260) import java.io.*;


261) class Dec2Roman
262) {
263) public static void main(String args[]) throws IOException
264) {
265) BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
266) System.out.print("Enter a Number : ");
267) int num=Integer.parseInt(br.readLine()); //accepting decimal number
268) if(num>0 && num<4000) //checking whether the number entered is within the
range [1-3999]
269) {
270) /*Saving the Roman equivalent of the thousand, hundred, ten and units place of a
decimal number*/
271) String thou[]={"","M","MM","MMM"};
272) String hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
273) String ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
274) String unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
275) /*Finding the digits in the thousand, hundred, ten and units place*/
276) int th=num/1000;
277) int h=(num/100)%10;
278) int t=(num/10)%10;
279) int u=num%10;
280) /*Displaying equivalent roman number*/
281) System.out.println("Roman Equivalent= "+thou[th]+hund[h]+ten[t]+unit[u]);
282) }

283) /*Displaying an error message if the number entered is out of range*/


284) else
285) System.out.println("nYou entered a number out of Range.nPlease enter a number in
the range [1-3999]");
286) }
287) }
288)

Source: http://www.javaforschool.com/165-program-on-decimal-to-roman-number-
conversion-method-1/#ixzz3GlDxpqlV
289) Answers:
290) Answer 1.
291) 0 [because, the function number ( ) is returning the value of ‘n’, and as we know that
after the execution of the given while loop, the value of ‘n’ becomes 0. Hence, the answer
will be 0.]
292) Answer 2.
293) Lava [because, s1.substring(1,4) gives, “ava”. Hence, “L”+”ava” = Lava]
294) 3 [because, s1.charAt(6) will give ‘o’ and hence, s2.indexOf(‘o’) will give 3.]
295) Java forSchool students [Note: There will be no space between “Java for” and
“School students”]
296) -9 [because, the (ASCII value of J – ASCII value of S) = 74-83 = -9]
297) false [because, “Java for” and “School students” are not equal.]
298) Answer 3.
299) x=3500 [because, first (c>2550?1350:1500) is calculated and then the result is added
to the value of ‘n’. Since, 900 is not greater than 2550, so the result of (c>2550?1350:1500)
is 1500, which is then added to the value of ‘n’ i.e. 2000, and we get the answer as 3500.]
300) y=1350 [because, in this case, first the value of n+c is calculated and then
(n+c>2550?1350:1500) is calculated. Since, n + c = 2000 + 900 = 2900 which is greater
than 2550, so the result of (n+c>2550?1350:1500) is 1350.]
301)

1. String in Java is a?
a) class
b) object
c) variable
d) character array
2. Which of these method of String class is used to obtain character
302) at specified index?
a) char()
b) Charat()
c) charat()
d) charAt()
2. Which of these keywords is used to refer to member of base class
303) from a subclass?
a) upper
b) super
c) this
d) none of the mentioned
304) 4. Which of the below method of the String class can be used to test
305) string equality?
A) equals()
B) isEqual()
C) isequals()
D) equal()
306) 5. Which of the below method of the String class can be used to find
307) the total number of characters in the String?
A) chars()
B) size()
C) len()
D) length()
308) 6. What would be the output of the below code related to String
309) equality?
310) String s = new String("PraBhu");
311) String p = new String("PraBhu");
312) System.out.println(s == p);
A) true
B) false
313) 7. Choose the correct output of the below code about String –
314) Character Equality?
315) Character c = 'A';
316) String s = "A";
317) System.out.println(c.equals(s));
A) true
B) false
318) 8. Method used to take a string as input in Java?
A. next()
B. nextLine()
C. Both A. and B.
D. None of these
319) 9. Array in java is ___.
A. Collection of similar elements
B. Collection of elements of different types
C. The data type of consisting of characters
D. None of these
320) 10. Which of these is the correct method to create an array in java?
A. int[] arr = {1, 3, 5};
B. int[] arr;
C. arr = new int[] {3, 1, 8};
D. int arr[] = {1, 4, 6};
E. All of these
321) 11. Static variables in java are declared as ___.
A. final variables
B. new variables
C. Constants
D. All of these
322) 12. Wrapper class in java is ___.
A. Used to encapsulate primitive data types
B. Declare new classes called wrapper
C. Create a new instance of the class
D. None of these
323) 13. Boxing is ___.
A. Creating new box
B. Creating object
C. Converting primitive type of object instance
D. All of these
324) 14. The correct syntax to import the math library in java is ___.
A. import java.lang.math
B. import math
C. import java.math
D. All of these
325) 15. Which Java method is used to convert an object to string?
A. createString()
B. toString()
C. object.string()
D. newString()
326) 16. Which statement is correct for private member in Java?
A. Access outside the class is allowed
B. Any class can access
C. Declared using private keyword
D. All of these
327) 17. Which keyword is used to inherit classes in Java?
A. extends
B. inheritance
C. isChild
D. None of these
328) 18. What are packages in Java?
A. Methods of a friend class
B. Methods of the main class
C. Way to encapsulate a group of classes, sub-
packages, and
329) interface
330) D. All of these
331) 19. Which of these is a non-access modifier?
A. public
B. private
C. native
D. All of these
332) 20. The trim() method in Java used to ___.
A. Remove the given character
B. Remove the values after the given index
C. Remove leading and trailing spaces
D. None of these
333) 21. Which Java keyword is used to access features of a package?
A. get
B. import
C. extends
D. All of these
334) 22. The result of dividing by 0 in Java is ___.
A. Error
B. Exception
C. Infinite
D. None of these
335) 23. Which among the following best describes encapsulation?
a) It is a way of combining various data members into a single unit
b) It is a way of combining various member functions into a single unit
c) It is a way of combining various data members and member functions
into a single
336) unit which can operate on any data
337) d) It is a way of combining various data members and member functions that operate
on
338) those data members into a single unit
339) 24. 2. If data members are private, what can we do to access them from the class
object?
a) Create public member functions to access those data members
b) Create private member functions to access those data members
c) Create protected member functions to access those data members
d) Private data members can never be accessed from outside the class
340) 4. Which feature can be implemented using encapsulation?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Overloading
341) 9. Which among the following violates the principle of encapsulation almost always?
a) Local variables
b) Global variables
c) Public variables
d) Array variables
342) What package is a part of the wrapper class which is imported by default into all Java
343) programs?
a. java.lang
b. java.awt
c. java.io
d. java.util
344) Write a program in any programming language you to find the first non-repeated
345) character in a given String, for example, if the given String is "Java" then the first
nonrepeated
346) character is "J"

You might also like