Icse Theory Questions
Icse Theory Questions
● Java is a case sensitive language. Which is the most appropriate statement with
respect to this context?
a) Upper and lower case letters are distinguished.
b) Upper case letters are converted to lower case.
c) lower case letters are converted to upper case.
d) Java responds to switch case construct
● Feature(s) of Java include ...........
a) Interpreter based b) procedure oriented c) platform dependent d) WORA
● A Java program can run as a stand-alone application only if it has__________
a) void method b) an overloaded method c) a main methodd) return type method
● Assertion(A): In java statements written in lower case letter or upper case letter
are treated as the same.
Reason(R): Java is a case sensitive language.
DISCUSSION ON SYLLABUS
(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
● Read the following text, and choose the correct answer:
A class encapsulate Data Members that contains the information necessary to
represent the class and Member methods that perform operations on the data
member.
What does a class encapsulate?
(a) Information and operation
(b) Data members and Member methods
(c) Data members and information
(d) Member methods and operation
● int n = (int)25.29 is an example of :
(a) Boxing (b) Unboxing (c) explicit type conversion (d) implicit type conversion
● Assertion(A): The base class and derived class are the terms used in abstraction.
Reason(R): the concept of extending a class to obtain another class is called
inheritance.
(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
● Which of the following options correctly represents a valid constant or value in the
Java programming language?
a. "Hello, World!" b. 3.14.2 c. TRUE d. myVariable
(a) Only a (b) Both a and c (c) Both a and b (d) Both b and d
● The default value for float, char and Boolean data type is
a) 0.0f ,‘\u0000’ , false
b) 0.0 , ‘\u0000’ , true int/0 Arithmetic exception
c) 0.0f, ‘null’ , false +float/0 Infinity
d) 0.0 ,‘\t0000’ , true -float/0 -Infinity
● What does the expression float a = (float)35 / 0 generate?
a) 0 b) NAN c) Infinity d) Run time exception [ (c) Infinity ]
● What does the expression int a = 35 / 0 return generate?
b) 0 b) NAN c) Infinity d) Run time exception
● Arrange the following primitive data types in an ascending order of their size:
char , byte , double ,int
a) Int , double , char , byte
b) byte , char , int , double
c) double , int , char , byte
d) byte , int , char , double
● Assertion (A) : byte b=(byte) 300 will store 300 in b
● Reasoning(R) : It will store 44. As 300 is bigger than byte range (-128 to 127) So it
stores (300-256) which is 44
(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
● T
h
e
e
x
p
r
e
s
s
i
o
n
w
h
i
c
h
u
ses > = operator is known as:
(a) relational (b) logical (c) arithmetic (d) assignment
● Ternary operator is a:
(a) logical operator (b) arithmetic operator (c) relational operator
(d) conditional operator
● Assuming x = 1 with the following code snippet:
int y = x--;
Which one of the following is true?
DISCUSSION ON SYLLABUS
a) x=1 , y=1 b) x=0 y=0 c) x=1 y=0 d) x=0 y=1
● Operators with higher precedence are evaluated before operators with relatively lower
precedence. Arrange the operators given below in order of higher precedence to lower
precedence.
(i) && (ii) % (iii) >= (iv) ++
a) (iv), (i), (iii), (ii) b) (iv), (iii), (ii), (i) c) (iv), (ii), (iii), (i) d) (i), (ii), (iii), (iv)
● Predict the output for the following expression !(2>3&&4>6 )
a) TRUE b) FALSE c) true d) false
● Choose the odd one out : 1. > 2. = = 3. &&d. !=
a) 1 b) 2 c) 3 d) 4
● String x = (a >= 90) ? "excellent" : "best"; when a = 90
a) best b) excellent c) excellentbest d) null
● To access the instance variables and methods of class objects in java _________ is used.
(a) Relational operator (b) Logical Operator (c) Dot operator(.) (d) New Operator
● Predict the output
● Assume that i = 1, j = 2, k = 3, and m = 2. What does each of the following statements print?
i. System.out.println( k + m < j | | 3 – j >= k );
ii. System.out.println( !( k> m ));
i)5<2 || 1>=3 false || false = false (ii)3>2 true !true=false
● What will be the result stored in x after evaluating the following expression? [2012]
int x=4; x+=(x++) + (++x) + x;
x=4+(4 + 6 + 6) = 20
● What is the result produced by
a) 2 – 10*3 + 100/11? Show the steps. b) 5 - 15 +5 * 9 % 6 + 23 / 4
c) ((300%(int)'A')+100%'1'))/5 a) -19 b) -2 c) 8
5. Input in Java
i) Initialization, Parameter, ii) introduction to packages,
iii) Scanner class iv) types of errors v) types of comments
● Method that accepts a string without any space is _______
a) next() b) nextLine() c)nextInt() d) nextString()
● Name the package that contains wrapper classes:
(a) java.util (b) java.lang (c) java .io (d) java.awt
● The method of Scanner class used to accept a double value is:
(a) nextInt() (b) nextDouble() (c) nextdouble() (d) NextDouble()
● Which of the following is a valid comment statement in Java
(i) /* comment */
(ii) /* comment
(iii) // comment
(iv) */ comment */
a) (i) & (iii) b) (i) & (ii) c) (iii) & (iv) d) (iii) & (ii)
● Name the type of error in the statement given below:
int r=100/0;
a) Syntax b) Runtime c) Logical d) All of the above
● Which of the following package is needed to find the square root of a number?
a) java.text b)java.mathc)java.lang d) java.util
● Assertion (A) : Division by 0 is a run time error
Reasoning (R) :Runtime error usually takes place when the syntax is incorrect
(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
(a+b)/(a-b) +Math.pow(a,b)/Math.pow(b,a)
(-b+Math.sqrt(b*b-4*a*c))/(2*a) ( -b-Math.sqrt(b*b-4*a*c))/(2*a)
● The following code segment should print “You will fare well in your ICSE exam” if
you have worked hard (wh) and practiced sample papers(sp). However, the code has
errors. Fix the code so that it compiles and runs correctly.
String wh = false , sp= true;
if (wh || sp) !wh&&sp
System.out.println("You will fare well in your ICSE exam ");
else
System.out.println("Difficult");
● Predict the output
int a=3;
switch(a++){
case 3:
System.out.println(a+4);
case 4:
System.out.println(a--*4);
default:
System.out.println(a);
(a) 8 (b) 8 (c) 16 (d) 7
16
3
● Predict the output
int a=200, b=5;
if (a%b == 0)
if (b/a == 0)
System.out.println (a/b);
else
System.out.println (a%b);
else
System.out.println (a*b);
(a) 0 (b) 40 (c) 1000 (d) Syntax error
● Assertion (A) : default is an optional statement in switch...case
DISCUSSION ON SYLLABUS
Reasoning (R) : Because absence of default leads to fall through
(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
● The following code segment checks if the given year is a leap year or not.
However the code has errors. Fix the code so that it compiles and runs correctly.
booleanisLeapYear = 0;int divisor; booleanisLeapYear = true/false
if (year % 100 == 0) divisor=400;
else divisor=4;
isLeap = year%divisor ==0? true:false;
if (isLeapYear=true) { ==
System.out.println(year + " is a leap year.");
DISCUSSION ON SYLLABUS
} else {
System.out.println(year + " is not a leap year.");
}
● Rewrite the code using ternary operator
if(color==’R’ || color==’r’)
System.out.println(“RED”);
else if(color==’G’ || color==’g’)
System.out.println(“GREEN”);
else if(color==’B’ || color==’rb)
System.out.println(“BLUE”);
else
System.out.println(“Invalid Input”);
● Assertion: The following for loop is invalid and will produce syntax error
for( i=1 , j=2; i<=10; i=i+1,j=j+2)
Reason: The loop is a modified for loop where two variables are used and is valid. The loop will stop
executing when i reaches value 11
(a) Both the assertion and reason are correct, and the reason is a correct explanation of the
assertion.
(b) Both the assertion and reason are correct, but the reason is NOT a correct explanation
DISCUSSION ON SYLLABUS
of the assertion. 0 (0-0)
(c) The assertion is correct, but the reason is incorrect. 0 (1-1)
(d) The assertion is incorrect but the reason is correct -2 (2-4)
-6 (3-9)
● Predict the output and the number of times the loop runs: -12 (4-16)
class Test {public static void main() {
int i;
for(i=0;i<5;i++)
System.out.println(i-i*i);
}}
● Which of the following for loop will not execute at least once?
(a) for(; ;) (b) for(a = 0; a < 1; a--) (c) for(a = 0; a>=0 ; a++) (d) for(a = 1; a < 1; a++)
● How many times will the following loop execute? What will be the output?
int x=2;
int y=50;
12 15
do{
X 3 (4) 5 (6) 7 (8) 9 (10) 11(12)
++x;
Y 50-3 47-5 42-7 35-9 26-11
y-=x++;
47 42 3526 15
}
while(x<=10);
System.out.println(x+” “+y);
● n=1000; n>10 1000>10 true 100>10 true
while (n>10) 10>10false
{ n=n/10; n 100 10
}
System.out.println(n); How many time the loop is executed and what is the output?
a) Loop is executed 2 times and the output is 100
b) Loop is executed 3 times and the output is 10
c). Loop is executed 2 times and the output is 10.
e) Loop is executed 2 times and the output is 0
● Ajay wrote the following program code and the answer he expected was to print the 1st 20
even numbers. But the code did not give him the correct answer.
a) Name the type of error he made b) Correct it so that the program runs properly
for(i=1;i<=20;i=i+2) i<=40 i=i+1 Logical error
{ if(i/2==0) i%2==0
System.out.println(i);
}
● How many times will the following code print "Java"?
for (int i = 1; i<= 5; i ++);
System.out.println("Java");
(a) 0 b)1 c) 5 d) 4
● Which of the following is an empty loop?
a) for(i = 0; i< 5; i++); b) while (++i< 5){ } c) do {} while (i++ < 5); d) All of these
● How many times will the inner and outer loop execute and predict the output
for(int i=1;i<=1000;i=i*10) 1235 124 13 2
{ for int j=1234;j>0;j=j/10) 1244 133 22 11
{ System.out.print(i+j+” “);} 1334 223 112 101
System.out.println(); 2234 1123 1012 1001
}
● How many times will the loop execute and predict it’s output
int a=2;
c
char b='a'; g
for (;a<=8;a+=2) m
System.out.println (b+=a); u
● Predict the output of the following code
K 5 15 25 35 45 55
K%2=0 f f f f f exit loop
Print 5 15 25 35 45
class code
{ static int m=2,n=10;
int x,y;
public code(int a,int b)
{ x=a;y=b;}
public int calc()
{ int result=++m*n--;
return result;}
public void display()
{System.out.println(m+"\t"+n);
System.out.println(x+"\t"+y);}
public static void main()
{ inti=12,j=24;
code obj=new code(i,j);
int output=obj.calc();
System.out.println(output);
obj.display();
}}
10 Constructors
i) Definition of Constructor ii) characteristics iii) types of
constructors (Default constructor / parameterized constructor ) iv) use of
constructors v) constructor overloading vi) Difference between constructor
and method.
● The name of the constructor and the name of the class are ____
(a) Same (b) Different (c) Same or different does not matter (d) None of the above
(a)parameterised constructor
(b)Polymorphism
● Anand wants to enter any character and check it is an alphabet. If so he will convert it in
upper case. The code he has written is giving errors. Identify the errors
import java.util.*;
class Code
{ public static void main()
{ char c;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter any character”)
c=sc.nextChar();sc.next.charAt(0)
if(Character.isAlphabet(c))Character.isLetter(c)
c=c.toUpperCase();Character.toUpperCase(c)
}}
● The return type of isWhitespace(char) is
a) char b) int c) boolean d) String
●
(c )Character
DISCUSSION ON SYLLABUS
(b) java.util
●
● (c)Unboxing
false
false
● class Test
{ K A
public static void main() {
char ch = 'a';
char chr = Character.toUpperCase(ch);
int n = (int) chr + 10;
System.out.println((char)n+"\t" + chr); }}
12. Encapsulation
i) Access specifiers private, protected and public.and its scope and
visibility ii) class variables, instance variables, argument
variables,local variables
● Akash wants the members of his class Employee to be accessible only to his class
“Employee”, what access specifier he should use for the members
(a) private (b) protected (c) public (d) default
13. Arrays
i) Definition of an array, types of arrays, declaration, initialization
ii) accepting data and accessing the elements of single and
double dimensional arrays iii) Single dimensional array sorting bubble
and selection iv) Linear and Binary Search in a single dimensional
array v) Finding sum of rows , columns, diagonals in a double
dimensional array
DISCUSSION ON SYLLABUS
● Given an array a[]={25,12,45,92,8}. What will be the contents of the array after the first pass
of bubble sort
a) {12,25,45,92,8} b) {12,25,45,8,92} c) { 12,25,8,45,92} d) {12,8,25,45,92}
● Given an array a[]={25,12,45,92,8}. What will be the contents of the array after the first pass
of selection sort
b) {12,25,45,92,8} b) {12,25,45,8,92} c) { 8,12,45,92,25} d) {12,8,25,45,92}
● Which of the following will extract the last character of a string (str).
(a) char last = str.lastChar(); (b) char last = str.charAt(str.length());
(c) char last = str.charAt(str.length()-1); (d) char last = str.charAt(str.length-1);
Math.pow(2,3)=8.0