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

Class X Comp MCQ, Outputs, Programs 2022-23

Uploaded by

Krishna Kanodia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Class X Comp MCQ, Outputs, Programs 2022-23

Uploaded by

Krishna Kanodia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Choose the correct answer and write the (a) Java Source Code (c) Bytecode
correct option. (b) Java Compiler (d) Interpreter
(i) Which is not a true statement about arrays? (xiii) It is a composite data type because it
(a) An array expands automatically when it is full. requires to use its attributes.
(b) An array is allowed to contain duplicate values (a) class (b) object (c) integer (d) array
(c) An array understands the concept of ordered (xiv) The keyword to create an object of a
elements. class is
(d) An array uses a zero index to reference the (a) create (b) new (c) New (d) NEW
first element. (xv) To declare a method in Java, choose the
(ii) Give the output of the following statement. required components.
String myStr1="Hello"; String myStr2= "Hello"; (a) Modifier (b) Return type
System.out.println(myStr1.compareTo(myStr2)); (c) Method name (d) All of these
(a) 0 (b) 2 (c) 1 (d) 11 (xvi) It is used to implement class behaviours
(iii) Array is a .......... data type. that are not affected by the state of any
(a) integer (b) string (c) composite (d) mixed instance.
(iv) Which of the following concepts can be (a) static keyword (c) static method
used for encapsulation? (b) static data member (d) None of these
(a) Wrapping data fields with methods (xvii) Constructor’s syntax does not include
(b) Hiding data and internal methods using (a) return type (c) class name
access modifiers in a class (b) parenthesis (d) All of these
(c) Using interfaces (d) All of the above (xviii) These statements can be used to
(v) Variables that are shared by every modify the behaviour of conditional and
instances of a class are ....... iterative statements.
(a) public variables (c) instance variables (a) Jump statements (c) Iterative statements
(b) private variables (d) class variables (b) Selection statements (d) Switch statements
(vi) One benefit of encapsulation is (xix) Which of the following declaration and
(a) the implementation of the class will be smaller. initialization is the below line equivalent to?
(b) the implementation can be changed without String str=new String();
changing programs that use the class. (a) String str=""; (c) String str="0";
(c) the interface of the class will be smaller. (b) String str=null; (d) String str="\0";
(d) the interface can be changed without (xx) What is the output of the given code?
changing programs that use the class. double b¿−15.6;
(vii) In Java, a library of classes is called...... double a=Math.rint(Math.abs(b));
(a) a package (b) a folder System.out.println("a= "+a);
(c) a directory (d) an application (a) 14.0 (b) 15.0 (c) 16.0 (d) 17.0
(viii) Which of the following methods can be (xxi) Which of the following statements are
used to join two strings? incorrect?
(a) trim() (b) concatenate() (a) String is a class
(c) join() (d) concat() (b) String in Java are mutable
(ix) Give the output of the following functions. (c) Every string is an object of class String
String x="Computer"; (d) Java defines a peer class of String, called
String y="Applications"; StringBuffer, which allows string to be altered.
System.out.println(x.indexOf(x.charAt(4))); (xxii) What will be the output of the following
(a) 4 (b) 5 (c) 3 (d) 2 program?
(x) What is the final value stored in variable x? class Output { public static void main() {
double x=Math.ceil(Math.abs (-7.3)); ∫ a[ ]={6 ,5 , 4 , 3 ,2 , 1 }, x ; for ¿
(a) 7.0 (b) 8.0 (c) 6.0 (d) 9.0
{System . out . println(a [x ]); }}}
(xi) How many types of print statements are
(a) 1 (b) 1 2 3 4 5 6 (c) None (d) 1
there in Java?
2 2
(a) 2 (b) 3 (c) 4 (d) 5 3 3
(xii) Which of the following is a set of 4 4
programs that transforms source code into 5 5
byte code? 6
(xxiii) Cell numbers of a dimensional array are (iii) Suppose x1 and x2 are two double type
also known as …… variables, that you want to add as integers
(a) packets (b) blocks and assign to an integer variable. Construct a
(c) subscripts (d) compartments Java statement for doing so.
(xxiv) Name the type of error in the statement (iv) What will be the content of L after
given below: double x; y; z; executing the following code?
(a) Logical error (b) Syntax error String F 1=I#N#T#E#R , F 2 ;
(c) Runtime error (d) No error ¿ /¿ represents a space∈ F 1
(xxv) In Java, we can call functions through F 2=F 1.trim();
(a) 3 ways (b) 4 ways
(c) 5 ways (d) None of these
∫ L=F 2.length ();
(v) The following code has error(s). Rewrite
(xxvi) Give the output of the following
the correct code underlining all the
∫ x=2, y=4 , z=1 ; corrections made:
∫ result =++ z + y +++ x+ z++ ; ∫ x=2; y =10;
(a) 11 (b) 12 (c) 10 (d) 9 do ; {++ x ; y−¿ x−−;
(xxvii) set method is an example of }while(x <10)
(a) pure method (b) impure method
return y
(c) class method (d) None of these
(vi) The following code has error(s). Rewrite
(xxviii) What will be the output of the following
the correct code underlining all the
Java program?
corrections made:
class String Demo {
public static void main (){
∫ var=2, n=15 ;
do ;
char chars []={' a ' , ' b ' ,' c ' };
var=var +5 ; n=n∗2 ;
String s=new String (chars);
while var≤n;
System . out . println(s); }} (vii) Write the java statement for the following
(a) a (b) b (c) c (d) abc expression:
(xxix) Which of the following access specifier
must be used for class, so that it can be
inherited by another subclass?
3
z=x + y −
3
( zy )3

(a) public (b) private (viii) State the output of the following program
(c) Both (a) and (b) (d) None of these segment
(xxx) Java array can allocate ……… String s=Digital World , s 1=Smart art ;
(a) dynamic memory (b) static memory String a=s . substring(3 ,7);
(c) class method (d) None of these String b=s . substring ( 5 ) . toUpperCase ();
2. (i) What output do you think the following System . out . println ( a ) ;
code will produce, if Number is -5? System . out . println(b . equalsIgnoreCase(a));
if ( Number ≥0 ) (ix) Write the statements for each of the
if (Number=¿ 0) following
System . out . println(First String) ; a) Store a number 500 as string
else b) Convert the string into numeric value
System . out . println(Second String ); (x) Write the java statement for the following
System . out . println(Third String); expression:
System . out . println(Fourth String);
(ii) Rewrite the following code using while
d= ( √ 3 x + x2
a+b )
loop. (xi) Consider the following class
∫ x=1 , y=2 ; public class Myclass {
for(x=1 ; x≤14 ; x ++; y +¿ 1){ public static∫ a=4 , b=5 , c=6 ;
System . out . println ¿ public ∫ x=2 , y=2 ; }
System . out . println(null+ Complete); Name the variables for which each object of class
will have its own distinct copy.
(xii) Find the value if a=12 17 #****
++ a∗(a+++5)+3∗−−a 2. Define a class to accept values into a double
xiii) State the type of errors, if any in the array of size 20 and print the range of the array,
following statements. range is the difference between the largest and
a) switch(x<2) the smallest elements of the array.
b) int a=100, b=0; 3. Define a class to accept the names of 10
System.out.println(a/b); students in an array and check for the existence
(xiv) Write the java statement for the following of the given name in the array using linear
expression: search, if found print the position of the name, if
not found print the appropriate message. Also
d=
( ( a+b )2
√a+ b ) print the names which begins with the word "SRI".
4. A valid number is a number in which the
(xv) Write the output of the following program eventual sum of digits of the number is equal to 1.
segment e . g . , 352=3+5+2=10=1+0=1, then 352 is a
∫ i=2, j=5 ; valid number.
for ¿ Design a class ValidNumber to check if a given
while ( j %i!=0) number, is a valid number. Some of the members
j++; of the class are given below:
Class name: ValidNumber
System . out . println(i∗j);
Data member
(xvi) Write the output of the following program
n: To store the number
segment. Also, write how times loop will
Member functions/Methods
execute.
ValidNumber(): Constructor to assign 0 to n
∫ i=15 , j=10 ; void getnum(int nn): To assign the parameters
do { value to the number, n = nn
while ( j %i=¿ 0) int Sum_digits(int) : Returns the sum of the
; digits of a number
i−−; void dovalid(): Checks if the given number is a
System . out . println(i∗j); valid number by calling the function
}while(i!= j); Sum_digits(int) and display appropriate message
Define the main() function to create an object and
(xvii) What is the value of a after evaluating
call the functions accordingly to enable the task.
the following expression? If a=8, b=4
5. Write a program to print the following patterns.
a+ ¿ 8 %++ b+++b /2+ 4−b+++ b ;
i) 1 ii) A
(xviii) Write a java statement for each to
26 AA
perform the following tasks. 3 7 10 ABA
a) Find and display the position of the last 4 8 11 13 ACCA
space in a string s. 5 9 12 14 15 ADFDA
b) Extract the second character of the string s 6. A class SwapSort has been defined to perform
(xix) a) Differentiate between next() and string related operations on a word Some of the
nextLine() functions. members of the class are as follows:
b) Define dynamic binding (functions). Class Name: SwapSort
(xx) Write the output of the following code Data members/Instance variables
snippet. wrd: To store a word
String x , str=INFORMATION ; len: integer to store length of the word
x=str . concat ( PRACTICE); swapwrd: to store the swapped word
System . out . println(x . length()+ ); sortwrd: To store the sorted word
Member functions/Methods
System . out . println ¿Case()+ ¿ ;
SwapSort(): default constructor to initialise data
Programs
members with legal initial values
1. Write a program to print the following patterns.
void readword(): To accept a word in UPPER
i) 1 3 5 7 9 ii) * * * * #
CASE
5 7 9 11 ***#*
9 11 13 **#**
13 15 *#***
void swapchar(): To interchange/swap the first Sample Output: The final Array after joining is :
and last characters of the word in wrd' and stores 5 6 45 17 2 58 33 13 25 1 0 7 9
the new word in 'swapwrd’. The final Array after sorting is :
void sortword(): sorts the character of the 0 1 2 5 6 7 9 13 17 25 33 45 58
original word in alphabetical order and it in 11. A man is paid the hourly rate (R) for the first
'sortwrd' 35 hours; he works in a week. Thereafter, he is
void display( ): displays the original word, paid at 1.5 time that hourly rate (R) for the next 25
swapped word and the sorted word. hours he works in a week, and at twice the hourly
Define the main() function to create an object and rate (R) for a further 10 hours in a week. He is not
call the functions accordingly to enable the task. allowed to work for more than 70 hours in a week.
Taking the number of hours worked (H) and the
7. Write a program in Java to print first 10 even rate per hour (R) as inputs, the weekly wages (W)
terms of the fibonacci series. are to be calculated and printed. Write a JAVA
Fibonacci series begins with 0 and 1 and every program for the above situation and print the
next term can be obtained by adding previous two weekly wages.
terms. e.g., 0,1,1,2,3,5,8,13, …. 12. Define a class HireCar with following
The output of your program should be 2,8,34, … descriptions.
ten terms. Data Members
8. Design a class to overload a method Number( ) Name : Name of the person
as follows: type : Type of A/C cab (DZIRE/ETHIOS
(i) void Number (int num , int d) - To count and or INNOVA)
display the frequency of a digit in a number. hour : Proposed hours(4 Hr or 8 Hr) for
Example: num = 2565685 which car is taken on rent
d=5 extrahour : Extra hour taken beyond the
Frequency of digit 5 is 3 proposed hour of rent
(ii) void Number (int n1) - To find and display the rent : Total rent inclusive of driver
sum of even digits of a number. allowance for hiring car
Example: n1 = 29865 Member Methods-
Sum of even digits = 16 HireCar(): Default Constructor
Write a main method to create an object and HireCar(…): Parameterized constructor to accept
invoke the above methods type of ac cab, proposed hour of rent, extra hour
9. Write a menu driven program in Java to input a taken beyond the proposed hour of rent.
number and check whether it is a: Calculate(): Function to calculate rent as per
(a) To find the sum of the series given below: following tariff
x x x
2 3 Type of A/C Cab 4Hr 8 Hr Ext/Hr
S=1+ + + +¿ up to n terms (Where x and Rs. Rs. Rs.
1 ! 2 ! 3!
n are to be inputted from the user) DZIRE/ETHIOS 800/- 1600/- 125/-
[Note: ! denotes the factorial of a number which INNOVA 1100/- 2100/- 160/-
is equal to the product of the numbers Driver Allowance of Rs100/- is added to the total
starting from 1 till that number. Example: 5! = 1 x rent
2 x 3 x 4 x 5] Display(): displays the rent by calling calculate
(b) DUCK number or not function along with other details
DUCK: A Duck number is a number which has of hiring a car.
zeroes present in it, but there should be no 13. Write a menu driven program to check if
zero present in the beginning of the number. number entered by user is
For example, 3210, 7056, 8430709 are all Duck a) Supersix Number – A number which contains
numbers whereas 08237 is not. at least two or more sixes.
10. Write a program in Java to accept two integer b) Automorphic number – A number is said to
arrays from the user and join them into a third be automorphic if it is present as last digit(s) in
array. After joining the arrays, sort the final array the square of itself.
in ascending order using Bubble sort technique 14. Design a class to overload the function
Sample Input: Array A [ ] = {5,6,45,17,2,58,33}; display( ) as follows:
Array B [ ] = {13,25,1,0,7,9};
a. void display(String s): print all letters are in
capital if word is in uppercase otherwise print in
lowercase
b. void display(String s, char ch): display the
1st half portion of the word if ch=’t’ else display
the last half portion of the word. This word must
consist of even number of characters .if s= “good”
and ch= ‘t’, output “go” otherwise output “od”
c. void call(): accept the required input and call
the functions.

You might also like