0% found this document useful (0 votes)
19 views6 pages

Mock Test 04

The document is a mock test consisting of multiple-choice questions and programming tasks related to Java programming concepts. It covers topics such as data types, methods, arrays, and control structures. Additionally, it includes practical coding exercises to evaluate the understanding of Java syntax and logic.

Uploaded by

dakshbhardwajjjj
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)
19 views6 pages

Mock Test 04

The document is a mock test consisting of multiple-choice questions and programming tasks related to Java programming concepts. It covers topics such as data types, methods, arrays, and control structures. Additionally, it includes practical coding exercises to evaluate the understanding of Java syntax and logic.

Uploaded by

dakshbhardwajjjj
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/ 6

MOCK TEST 04: FINAL

Section A (Attempt all Q’s)

1. MCQ Type Questions [20]


i) What will be the output for:
System.out.print(Character.toLowerCase('1'));
a) 0 b) 1
c) A d) true

ii) 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 true and Reason (R) is false
d) Assertion (A) is false and Reason (R) is true

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

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

(v) The method compareTo() returns ............... when two strings are equal
and in lowercase :
a) true
b) 0
c) 1
d) false
vi) Which of the following is a valid Integer constant:
i. 4
ii. 4.0
iii. 4.3f
iv. "four"

a) Only i
b) i and iii
c) ii and iv
d) i and ii

vii) The expression which uses >= operator is known as:


a) relational
b) logical
c) arithmetic
d) assignment

viii) Ternary operator is a:


a) logical operator
b) arithmetic operator
c) relational operator
d) conditional operator

ix) The number of bytes occupied by a character array of 10 elements.


a) 20 bytes
b) 60 bytes
c) 40 bytes
d) 120 bytes

x) Among the following which is a keyword:


a) every
b) all
c) case
d) each

xi) ............... class is used to convert a primitive data type to its


corresponding object.
a) String
b) Wrapper
c) System
d) Math

xii) A single dimensional array contains N elements. What will be the last
subscript?
a) N
b) N – 1
c) N – 2
d) N + 1
xiii) Method that converts a character to uppercase is ............... .
a) toUpper()
b)ToUpperCase()
c) toUppercase()
d) toUpperCase(char)

xiv) The Scanner class method used to accept words with space:
a) next()
b) nextLine()
c) Next()
d) nextString()

xv) What value will Math.sqrt(Math.ceil(15.3)) return?


a) 16.0
b) 16
c) 4.0
d) 5.0

xvi) Write a method prototype name check() which takes an integer


argument and returns a char:
a) char check()
b) void check (int x)
c) check (int x)
d) char check (int x)

xvii) The output of the function "COMPOSITION".substring(3, 6):


a)POSI
b) POS
c) MPO
d) MPOS

xviii) The code obtained after compilation is known as:


a) source code
b) object code
c) machine code
d) java byte code

xix) Missing a semicolon in a statement is what type of error?


a) Logical
b) Syntax
c) Runtime
d) No error

xx) A method which does not modify the value of variables is termed as:
a) Impure method
b) Pure method
c) Primitive method
d) User defined method
2. Answer the following questions:[20]
a) Write the Java expression for (p + q)2.

b) Evaluate the expression when the value of x = 2: x = x++ + ++x + x

c) 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.

d) 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?

e) How many times will the following loop execute? What value will be
returned?
int x = 2;
int y = 50;
do{
++x;
y -= x++;
}
while(x <= 10);
return y;

f) Write the output of the following String methods: (a)


"ARTIFICIAL".indexOf('I')
(b) "DOG and PUPPY".trim().length()

g) Name any two jump statements.

h) Predict the output of the following code snippet:


String a = "20";
String b = "23";
int p = Integer.parseInt(a);
int q = Integer.parseInt(b);
System.out.print(a + "*" + b);

i) When there is no explicit initialization, what are the default values set for
variables in the following cases? (a) Integer variable (b) String variable

j) 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[ ] ?
(b) Write index position of first and last element?
Section B (Any four Q’s)

1. Define a class called Array having following member:


Data member:
array A of 10 integers, avg
Member functions:
1) readArray() – Input 10 arbitrary integers in array A
2) showArray() – Display array elements.
3) sel_sort() – Arrange array A in descending order by using selection sort
method.
4) findAvg() – Find the average of second smallest and second largest
elements of array
5) findValue(int z) – Find the ‘z’ element using binary search

2. Write a program that reads a string and a character. Each occurrence of the
given character (regardless of its case) is converted to opposite case.
For example:
Input string: Amrit Pal Aggarwal
Input character: A
Output: amrit Pal aggArwAl

3. Using the switch statement, write a menu driven program to print the
following pattern depending on the user choosing 1 or 2 for an incorrect
choice, an appropriate error message should be displayed:
1) AEIOU
AEIO
AEI
AE
A

2) 1
1 10
1 10 100
1 10 100 1000
1 10 100 1000 10000

4. Define a class to accept values into a 3x3 array and check if it is a special
array or not. An array is special array if the if any one element is special
element. 95 108 13
Example: 10 999 145
Fig (1): 145 is a special element, because 1! +4! +5!
505 365 2
=145. Therefore, the 3x3 array is a SPECIAL!
Fig (2): Since 145 is not present in the array therefore it isn’t a special array.
951 245 100
895 514 89
598 111 112
5. Write a program in Java to accept a string. First display its capital letter
followed by small letters, digits and then other characters.
Ex: Input = ChiefTwit@Twitter:ElonMusk2022
Output = CTTEMhiefwititterlonusk2022@

6. Define a class to accept a 3-digit number and check whether it is a duck


number or not.
Note: A number is a duck number if it has zero in it.
Example 1:
Input: 2083
Output: Invalid

Example 2:
Input: 103
Output: Duck number

You might also like