Page 272 - IT-802_class_12
P. 272
Ans. a. Syntax error
b. This loop is an infinite loop.
c. while( x <=5 )
8. What are String Class Methods in Java? Consider the statement [CBSE Sample Paper 2023]
String name = ‘‘Hello World’’.
Write a single line Java code using String methods to perform the following :
(a) Convert the name to lowercase.
(b) Replace “Hello” by “Welcome” in the given string.
(c) Check whether the name contains ‘‘Sin’’ in it or not
(d) Add a new string ‘‘jackpot” at the end of original string.
Ans. (a) name.toLowerCase( )
(b) name.replace(”Hello”,“Welcome”)
(c) name.contains(”Sin”)
(d) name.concat(”jackpot”)
9. Write a code in java using a for loop to display all odd numbers between 1 to 10. Is for loop an entry controlled loop or exit
control loop? [CBSE Sample Paper 2023]
Ans. for (int count = 1; count <= 10; count = count +2)
{System.out.println(count);}
Entry control loop
10. What is the need of a constructor in OOP? Explain all features of a constructor. [CBSE Sample Paper 2023]
Ans. A special method member called the constructor method is used to initialize the data members of the class.
Features
The constructor has the same name as the class, has no return type, and may or may not have a parameter list. Whenever
a new object of a class is created, the constructor of the class is invoked automatically. We do not call the constructor
explicitly.
11. Write the Mysql commands for the following queries: [CBSE Sample Paper 2023]
TRAIN
TrainID Station
0001 DELHI
0002 MUMBAI
COUNTER
TicketID Date Cost TrainNo
T1 12/3/22 500 0001
T2 15/5/22 450 0002
T3 15/5/22 500 0001
(a) To find all the stations, date for ticket id as T1.
(b) To find the total ticket amount collected from each station.
(c) To displays all the tables created in the current database.
(d) To delete table counter along with the information in it.
Ans. (a) SELECT , DATE FROM TRAIN, COUNTER WHERE TRAIN.TrainID=COUNTER.TrainNO and TicketID=”T1”;
(b) SELECT SUM(COST), STATION FROM TRAIN, COUNTER WHERE TRAIN.TrainID=COUNTER.TrainNO GROUP BY STATION;
(c) SHOW TABLES;
(d) DROP TABLE COUNTER;
270 Touchpad Information Technology-XII

