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

Icse Theory Questions

Uploaded by

das.arabinda1940
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
314 views

Icse Theory Questions

Uploaded by

das.arabinda1940
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

DISCUSSION ON SYLLABUS

1. Revision of Class IX Syllabus


(i) Introduction to Object Oriented Programming concepts, (ii) Elementary Concept of
Objects and Classes, (iii) Values and Data types, (iv) Operators in Java, (v) Input in
Java, (vi) Mathematical Library Methods, (vii) Conditional constructs in Java, (viii)
Iterative constructs in Java, (ix) Nested for loops.

1.Introduction to Object Oriented Programming concepts


i) a) Class b) Object c) Abstraction d) Encapsulation
e) Inheritance f) Polymorphism
Picture questions :Name the feature of java depicted in the picture below.
DISCUSSION ON SYLLABUS

g) Object oriented programming vrsprocedure oriented programming

ii) Introduction to JAVA (a) Types of java programs – Applets and


Applications, (b)Java Compilation process, Java Source code, Byte code,
Object code, Java Virtual Machine (JVM), (c) Features of JAVA

● Which component is used to compile, debug and execute java program?


a) JVM b) JDK c) JIT d) JRE [ (b) JDK]
● Which component is responsible for converting bytecode into machine specific code?
a) JVM b) JDK c) JIT d) JRE [ (a) JVM ]
● Which statement is true about java?
a) Platform independent programming language [a]
b) Platform dependent programming language
c) Code dependent programming language
d) Sequence dependent programming language
● What is the extension of java code files?
a) .class b) .java c) .txt d) .doc [ (b) .java ]
● What is the extension of compiled java classes?
a) .class b) .java c) .txt d) .js [ (a) .class ]
● Java program developed and executed using web browser is known as:
a) Application b) byte code c) object d) applet [(d) applet

● 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

2. Elementary Concept of Objects and Classes


a) attribute and behaviour b) message passing c) class as object factory d) object as
instance of a class

● The _________ is called an instance of a class


a) Object b) Attributes c) State d) message
● Objects communicate with one another through __________
a) Object passing b) object returning c) message calling d)message passing
● Objects are also called the ___________ of a class
a) Class factory b) blue print c) instance d) instantiation
● Assertion (A) :Class creates objects of similar type
Reasoning (R) : So it is called an object factory
(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

3. Values and data types


DISCUSSION ON SYLLABUS

a) Character set, b) ASCII code, Unicode, c) Escape sequences d)


Tokens e)Constants and Variables, f) Data types g) type conversions

● The size occupied by a boolean variable is:


(a) 1 byte (b) 2 byte (c) implementation dependent (d) 4 bytes (1 bit)
● If boolean x=true, then x.toString() will return
(a) true (b) “true” (c) ‘true’ (d) syntax error

● 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

● The statement System.out.println("Long live the \"King\"") will print


a) Long live the \"King\" b)Long live the \King\
c)Long live the "King" d) Syntax error
● Data types in Java are of different sizes and values that can be stored in the variable that is
made as per convenience and circumstances to cover up all test cases. Java has two
categories in which data types are segregated:
Primitive Data Type: such as boolean, char, int, short, byte, long, float, and double.
Non-Primitive Data Type or Object Data type: such as String, Array, etc.
Answer the following question related to the above text?
Give one example of Primitive and Non-Primitive Data types:
DISCUSSION ON SYLLABUS

(a) byte and long


(b) short and array
(c) double and char
(d) None of the above
● Sam executes the following program segment and the answer displayed is zero
irrespective of any non zero values are given. Name the error. How the program
can be modified to get the correct answer?
void triangle(double b, double h)
{ double a;
a = ½ * b * h;
System.out.println(“Area=”+a); }
Logical error (double)1/2

4. Operators in Java
i. Forms of operators (Unary/Binary/Ternary) ii. Types of operators
(Arithmetic / Relational/Logical/Assignment/ Increment,Decrement /
Short hand iii. Hierarchy of operators iv.‘new’ operator, dot operator.

● 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

6%2=0 p=2*(2%4)=4 p=4 q=4


● Give the output of the following code if a=9 and b=10
a -= a-- + ++a/ ++b * 4;
System.out.println (a);
a= 9-( 9+ 9/11 *4) = 9-9=0

● Predict output and explain why : Result42


System.out.println(“Result”+4+2); Result6
System.out.println(“Result”+(4+2));
6Result
System.out.println(4+2 +“Result”);

● 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

● Find the output and explain


System.out.println(-19 % 4); -3
System.out.println(-19 % -4); -3
System.out.println( 19 % -4); 3

● char x='A'; int m; [2010]


m=(x=='a') ? 'A':'a';
System.out.println("m=" + m); m=97
DISCUSSION ON SYLLABUS

● The expression a+=b


(a) is same as a=a+b(b) is same as a=b+b (c) is same as b=a+b (d) is same as a=b
● Predict the output
300>-200 true
100+0 == 200-100 true
!(200==200) false
100<200 && 500%100==0 true
& true=true
● Predict the output
X=2*5 = 10

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

6. Mathematical Library Methods


i) Introduction to package java.lang
DISCUSSION ON SYLLABUS

ii) methods of Math class.


pow(x,y), sqrt(x), cbrt(x), ceil(x), floor(x), round(x), abs(a), max(a, b),
min(a,b), random( ).
iii) Java expressions – using all the operators and methods of Math
class

● Math.max(29,12.5) will return


a) 29 b) 29.0 c) 12 d)12.5
● Return type of Math.round(double) is
a) double b) Double c) Integer d) int
● (int)Math.ceil(Math.random()*6) will generate numbers in the range
a) 0 to 6 b) 1 to 5 c) 0 to 5 d) 1 to 6

(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)

● Predict the output


12.34+25.0 = 37.34
-2.0-6.0= -8.0
Max(4.0,8.0)=8.0
0 to 9
Min(‘1’,’3’) =’1’
6+5=11
● System.out.println(Math.sqrt(-0)+" , "+Math.sqrt(-25)) will generate
a) 0, NaN b) 0 , Infinity c) 0.0 , NaN d) Runtime error
● Write a Java expression for the following: |x2+2xy|
(a) Math.abs((x*x)+(2*x*y)) (b) Math.abs(Math.pow(x , 2)+(2*x*y))
(c) Both a and b (d) None of the above
● Key word to call package in the program:
(a) extends (b) export (c) import (d) package

7. Conditional constructs in Java


i) Application of if, if else, if else if ladder ii) switch-case, default
break.
● Predict the output

a) “Executed “ b) Not Executed c) Executed d) Syntax error


● Predict the output
int a=5,b=10,c=15;
if(a*2==b) 10=10 t 5+15%6=8
System.out.println(a++ + c%a); 6%3==0 t 11*14/11 =14
if(a%3==0)
DISCUSSION ON SYLLABUS
System.out.println(++b*--c/b);
a) 8 b) 9 c) 8 d)8
0 14
● Rewrite using ternary operator
If(bill>=1000)
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;
a) bill>=1000? discount=bill*10/100 : discount=bill*5.0/100
b) bill < 1000? discount=bill*10/100 : discount=bill*5.0/100
c) discount ==bill>=1000? bill*10/100 : bill*5/.0100
d) discount = bill>=1000? bill*10/100 : bill*5.0/100
● The following code segment should print “You can go out” if you have done
your homework (dh) and cleaned your room(cr). However, the code has errors.
Fix the code so that it compiles and runs correctly.
boolean dh = True; true
booleancr= true;
if (dh &&cr)
System.out.println("You cannot go out"); can
else
System.out.println("You can go out"); cannot

● 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

● What will be the output of the following java program


String str="RAM";
switch (str)
{
case "ROM": System.out.println ("Read Only Memory");
case "RAM": System.out.println ("Random Access Memory");
case "DRAM": System.out.println ("Dynamic Random Access Memory");
default: System.out.println ("Types of memories");
(a) Random Access Memory
Dynamic Random Access Memory
Types of memories
(b) Random Access Memory
(c)Random Access Memory (d) Syntax error
Dynamic Random Access Memory

● Rewrite the above code using if..elseif..else statement

● State the output of the code for


int x=10;
if(x++ == 11)
System.out.println("Result is 11");
else if(++x == 10)
System.out.println("Result is 10");
else if(- - x == 10)
System.out.println("Result is Ten");
else
System.out.println("Result is neither 10 nor 11");
(a) Result is 11 (b) Result is 10 (c) Result is Ten (d) Result is neither 10 nor 11

● Read the following text, and choose the correct answer:


In Java, the "switch" statement is used for multi-way branching based on the
value of an expression.
Which of the following is true about the "switch" statement in Java?
(a) It can only be used with integer and String type data types.
(b) It can be used with both integer and floating-point data types.
(c) It can be used only with wrapper data types.
(d) It can only be used with boolean data types.

● 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”);

8. Iterative constructs in Java


i) Definition ii) Types of looping statements, entry controlled loops [ for, while]
iii) exit controlled loop [do while] iv) variations in looping statements v)Jump statements. vi)
Nested loop
● Assertion: The "break" statement in Java is used to terminate the current iteration of a loop.
Reason: Presence in “break” statement in Java prevents fall through
(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
of the assertion.
(c) The assertion is correct, but the reason is incorrect.
(d) The assertion is incorrect but the reason is correct

● Assertion: for(int i=1; i<=10; i=i-1) is an example of infinite loop


Reason: The value of the control variable is decreasing by 1 and will never reach 10
(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
of the assertion.
(c) The assertion is correct, but the reason is incorrect.
(d) The assertion is incorrect but the reason is correct

● Assertion: do .. while is an exit controlled loop


Reason: In a loop the condition is checked while entering the loop .If it is true the then the
loop is executed
(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
of the assertion.
(c) The assertion is correct, but the reason is incorrect.
(d) The assertion is incorrect but the reason is correct

● 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
}

● Rewrite the above code using a) while loop b) do while loop


● Predict the output
DISCUSSION ON SYLLABUS
for(int i=1;i<=5; i++) A
{ for int j=1;j<=i;j++) BB
{ System.out.print((char)(i+64));} CCC
System.out.println(); DDDD
} EEEEE
● Predict the output of the following snippet
int a=100; 100
do
80
{
if(a%3==0) 100 80
break;
System.out.println (a);
a=a-20;
}while (a>=1);

● 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

9. User - defined Methods


i) Need of methods ii) method definition signature /prototype/return type ,
iii) forms of method pure/impure , static / non static iv)method calling
actual/formal parameter , call by value/call by reference iv)method
overloading

● Given the code:


int add(int a, int b)
{
int s=a+b;
return s;
}
The statement to call the above function will be
(a) add(10,20); (b) int sum=add(10,20); (c) int sum=add(10.5,20.5); (d) add(10.5,20.5);

● Invoking a method by passing the objects of a class is termed as


(a) Call by value (b) call by reference (c) call by method (d) call by object

● The following keyword makes a variable class variable


a) public b) protected c) static d) final
DISCUSSION ON SYLLABUS
● Assertion(A): call by value is known as pure method
Reason(R): The original value of variable does not change as operation is
performed on copied values.
(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 false and Reason (R) is true
(d) Assertion (A) is false and Reason (R) is true

● Which of the following return statement is incorrect


a) return 0 b) return(s) c) return(s,p) d) return(s+p)
● Which of the following is a correct prototype of a function check which receives
a character ch and integer n and returns true or false?
a) int check(char ch,int n) b) boolean check(char ch,int n)
c) int check(char , int) d) void check(char ch,int n)
● Assertion (A) :In call by reference , the address of the actual parameters is passed to the
function as the formal parameters
Reason (R) : In call by reference change in formal parameter is reflected to the actual
parameter
● 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 false and Reason (R) is true
(d) Assertion (A) is false and Reason (R) is true

● Study the class and answer the questions that follow

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();
}}

i)The class variables are


(a) m (b) m and n (c) x and y (d) a and b
ii) The instance variables are
(a) m (b) m and n (c) x and y (d) result and output
iii) The formal parameters are
(a) a and b (b) m and n (c) i and j (d) result and output
iv) ) The actual parameters are
DISCUSSION ON SYLLABUS
(a) a and b (b) m and n (c) i and j (d) result and output

v) Predict the output when the main method is invoked


30
3 9
12 24
 A method which does not modify the value of variables but does not return any value
(a)Impure method (b) pure method (c) user defined methods (d) call by reference

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

● If a constructor has a return type then the result will be


(a) Runtime Error (b) Compilation Error (c) Code will run successfully (d) Code runs
successfully with primitive type but produces error with non-primitive type
● A class description is given below
class Myclass
{ //member data
String n;
int r; }
1. The default constructor can be defined as
a) Myclass(String nn,int rr) { n=nn;r=rr;}
b) Myclass() { n=””;r=0;}
c) Myclass(Myclassob) { n=ob.n ; r=ob.r; }
d) All are correct

2. The parameterised constructor can be defined as


a) Myclass(String nn,int rr) { n=nn;r=rr;}
b) Myclass() { n=””;r=0;}
c) Myclass(Myclassob) { n=ob.n ; r=ob.r; }
d) All are correct

(a)parameterised constructor

● Which of the following is not true for a constructor


a) Constructor is invoked during object creation
b) Constructor name must be the same as its class name
c) A Constructor is a special kind of method
DISCUSSION ON SYLLABUS
d) A Java constructor can be abstract, static, final

(b)Polymorphism

11. Library classes


i) Introduction to wrapper classes ii) methods of
wrapper class and their usage with respect to iii) numeric and character
data types. Autoboxing and Unboxing in wrapper classes
● Predict the output 120100
String m="120",n="100"; 20
System.out.println(m+n);
120100.0
System.out.println(Integer.parseInt(m)%Integer.parseInt(n));
System.out.println(Double.parseDouble(m+n));

 Predict the output true


String s="YEAR 2023"; true
System.out.println(Character.isLetterOrDigit(s.charAt(5))); r
System.out.println(Character.isWhitespace(s.charAt(4)));
System.out.println(Character.toLowerCase(s.charAt(3)));

● 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

● Consider the following code


class Variable
{ inta,b;
Variable()
{ a=15;b=20;}
void method()
{ int a=99 , b=77;
System.out.println(“a="+a+"b="+b);}
DISCUSSION ON SYLLABUS
void display()
{ System.out.println("a="+a+"b="+b);}
}
1) What will be the output when void display() is invoked
a) a=99 b=77 b) a=15 b=20 c) a=0 b=0 d) Syntax error
2) What will be the output when void method() is invoked
b) a=99 b=77 b) a=15 b=20 c) a=0 b=0 d) Syntax error

● 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 members of the class
c) private members of class can be inherited by a subclass, and become protected members in
subclass [ private members cannot be inherited]
d) protected members of a class can be inherited by a subclass, and become private members
of the subclass

● Assertion: In Java, the "static" keyword is used to declare instance variables


Reason: These variables are shared by all the objects of the class and are known as class
variables.
Which option correctly describes the relationship between Assertion and Reason?
(a) Both Assertion and Reason are true, and Reason is a correct explanation ofAssertion.
(b) Both Assertion and Reason are true, but Reason is not a correct explanation ofAssertion.
(c) Assertion is true, but Reason is false.
(d) Assertion is false, but Reason is true.

● Method which is part of a class rather than instance of a class is termed as


a) Non static method b) pure method c) impure method d) static method

● Predict the output when main() is invoked


class Output
{ public static int x=0;
Output()
{ x=x+1;} Ob1 x=1
void display() Ob2 x=2
{ System.out.println("x="+x);} as it is static
public static void main()
{ Output ob1=new Output();
Output ob2=new Output();
ob2.display(); } }
a) x=1 b) x=2 c) x=0 d) No output

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

● Java statement to access the 5th element of an array is:


(a) X[4] (b) X[5] (c) X[3] (d) X[0]
● Consider the given array and answer the questions given below:
int x[ ]={4,7,9,66,72,0,16};
(a) What is the length of the array?7
(b) What is the value in x[4]?72

 Predict the output for the following code


int arr[]={12,10,5,8,7};
12
System.out.println(arr.length+arr[arr.length-1]); 40
System.out.println(arr[0]++ + --arr[2]*arr[4]); 13 10 4 8 7
for(int i=0;i<arr.length;i++)
{ System.out.print(arr[i]+" ");}

● The array int x[10] occupies


a) 10 bytes b) 40 bytesc) 20 bytes d) 80 bytes
● What will be the output of the code
char x[]={65,66,32,68,67};
System.out.println(x[0]+” “+x[3]);
AD
System.out.println(++x[1]); C
for(int i=0;i<x.length;i++) AC DC
{ System.out.print((char)x[i]);}

● What will be the output


class Output
{ public static void main()
{ boolean b[]={true,false,true};
for(int i=0;i<b.length;i++)
{ if(b[i]) System.out.print(i+"."+b[i]);} } }
a) 0.true2.false b) 0.true 1.false c) 1.false d) 0.true2.true

● The array double a[2][3] occupies


b) 48 bytes b) 16 bytes c) 24 bytes d) 40 bytes
● Number of rows in a two dimensional array arr[][] is
a) arr.length b) arr.length() c) arr[0].length d) arr[].length
● Number of columns in a two dimensional array arr[][] is
b) arr.length b) arr.length() c) arr[0].length d) arr[].length
● What will be the final value stored in array a[] after execution of the above code
int a[]={2,4,6,8,10};
for(int i=0;i<a.length-1;i++) 5 7 9 11 11
{ a[i]=++a[i+1];}

● Assertion: Binary search technique is faster than linear search technique


Reason: Binary search works on sorted array
Which option correctly describes the relationship between Assertion and Reason?
(a) Both Assertion and Reason are true, and Reason is a correct explanation of
Assertion.
(b) Both Assertion and Reason are true, but Reason is not a correct explanation of
Assertion.
DISCUSSION ON SYLLABUS
(c) Assertion is true, but Reason is false.
(d) Assertion is false, but Reason is true.

● 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}

● int P [ ]={ 12,14,16,18}; int Q[ ]={ 20,22,24};


Place all elements of P array and Q array in the array R one after the other.
(a) What will be the size of array R [ ] ? 7
(b) Write index position of first and last element? 0,6

14. String handling


i) String class ii) methods of String class iii)implementation of String class
methods iv)String array
● Which of the following is to be used for comparing two strings (s1 and s2) without any
distinction between the case:
(a) s1 == s2 (b) s1.compareTo( s2 ) (c) s2.equalsIgnoreCase(s1) (d) s1.equals(s2)

● The output of “World cup2023”.substring(7, 9) is:


(a) cup (b) up2 (c) up (d) cup2

● 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);

● Predict the output


mittittippi
23

● Predict the output of the following code


9
true
A
true
BASIC BASE
BASE
4
i
SE
MAGIC
DISCUSSION ON SYLLABUS

● Predict the output

Math.pow(2,3)=8.0

● Predict the output of the following code


4
false
true
true
ME
AM
11

You might also like