You are on page 1of 9
ASHGKA ASHOKA GROUP OF SCHOOLS, Ashoka Marg Academic Session 2023-2024 Grade X Marks: 50 Slip Test3. Computer Application 19" Dec 2023. Time: 1 Hour Topic:Encapsulation, Strings, Arrays Question 1: Multiple choice questions [Marks 15] 1. Which of the following is a valid statement for declaring an array of type char? a) char{ ] e=new char(); ©) charf ] c=new char(4); ) char{ J e=new charf Js ) char ] c=new char [4]; 2. Which of these is necessary to specify at time of array initialisation? a) Row cc) Both row and column b) Column d) None of the above °) 3. Which variables are initialised inside a method, block or constructor? a) Local Variable cc) Instance Variable b) Class variable 4) Static Variable 4, Which element is represented by af5]? a) sth oa b) ot a) th 5. What will be the output of the following? int x{] = {12,13,14,15,16}; Systemoul.printIn(x{2] +" "+ x{4)); a) 14 16 ©) 13 15 b)30 4) 1415 6. The number of bytes occupied by a character array of 10 elements. a) 20 bytes ©) 40 bytes b) 60 bytes 4) 120 bytes 7. int af]={4,8,7,12,3} System.out printIn(a[2+1]); a) 12 ©) 10 b) 14 ail 8. Which of the following statements is the most appropriate for the private members? a). They are visible out of the class in which they are defined. b) They can be used in the sub-classes. 2023-24/Grade- X /Slip Test 3/Computer Application Page 1 of 9 ©) They are only visible in the class in which they are declared. 4) They can be used in same package 9. Assertion(A); Array is a datatype which can store multiple values of similar type. Reason(R): int arr{J= { 1,2, 3, 4,5}; is an example of an array. 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) ©) Assertion (A) is true and Reason (R) is false 4) Assertion (A) i false and Reason (R) is true 10. is the name of the array when it is used with a subscript to access a singk element of the array. a) actual variable ¢) subseripted variable b) primitive variable ) array variable 11. If the number of locations reserved for an array is 59, the maximum no of elements that can be stored in this array are: a) 58 ©) 60 b) 59 4) More than 60 12. Assertion(A); for array arr{}={1,2,3} ; arr. ength () will give output as 3. Reason(R): The kength attribute of an array provides a quick way to obtain its size. 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 fae 4) Assertion (A) is false and Reason (R) is true 13, The image depict which type of datatpe a) class c) Arrays. b) String 4) interfice 2023-24/Grade- X /Slip Test 3/Computer Application Page 2 of 9 14, Assertion(A); to display all the elements of the array we can use the following. for loop for(int i-li<-n;i++) where nis the size of the array Reason(R): Arrays in Java use zero-based indexing, meaning the first element is accessed with index 0, the second with index 1, and so on. 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 4) Assertion (A) is false and Reason (R) is true 15. Out of the following statements which is not correct in respect to arrays a) The size of an array in Java is fixed upon creation and cannot be changed afterward b) While the size of an array is fixed, its elements can be dynamically initialized ©) Arrays in Java can store both primitive data types (int, char, ete.) and objects. d) Arrays is a heterogenous data structure. 16. Consider the following declaration String line = "Some more interesting. stuff on strings!" 1/ the words are separated by a singke space What string will str refer to after execution of the following code segment? int x = fine indexOf"m"); String str = line.substring(10, 15) + line substring(25, 25 + x); a) interest c) inter ff b) interft 4) intert 17. A program has a String variable filName that stores a first name, followed by a space, followed by a last name. There are no spaces in before or afler the first or last names. Here are some exampks of fulName values: "Anthony Coppola", “Jimmy Carroll" and "Tom DeWire" . Consider the following code segment that extracts the last name fom a fillName variable, and stores it in lastName with no surrounding blanks: int k = fullName.indexO f{" ") // find index of blank String lastName = /* expression */ Which is a correct replacement for /* expression */ ? 1. fallName.substring(k); I. filName.substring(k + 1); TIL fullName.substring(k. + 1, fillName. length); b) Tonly a) Lonly 4) [and IIT only c) Wand 111 only 2023-24/Grade- X /Slip Test 3/Computer Application Page 3 of 9 18. This question refers to the getString method shown below: public static String getString(String st, String s2) { int index = s1.indexOfs2); retum sI.substring(index, index + s2.length()); 4 Which is true about getString, where s1= computer and s2=compute? It may return a string that ... 1... is equal to 52. I. ... has no characters in common with s2. IL... is equal to sl a) [and IIT only ©) I and II only b) 1.1, and IIT ¢) Tonly 19. public class StrEqual { public static void main) new String(""hello"); "hello"; 32) { Systemout-printIn("s1_ and s2 equal’); } ebe { Systemout.printin("s! and s2 not equal); i if (s1 =s3) t Systemout-printIn("s1_ and s3 equal’); } ebe Systemout.printIn("S1 and s3 not equal"); 4 ' } Which one of the following options provides the output of this program when executed? a) sl and s2 equal sl and s3 equal b) sl and s2 equal s1 and s3 not equal °) sl and s2 not equal sl and s3 equal d) sl and s2 not equal sl and s3 not equal 2023-24/Grade- X /Slip Test 3/Computer Application Page 4 of 9 20. public class Test { public static void main(String{] args) { String s= new String("5"); Systemout printIn(1 + 10+s+1+ 10); } i a) 11511 ©) 15110 b) 1105110 d)27 21. Which of the following methods is used to compare two strings for equality in Java? a) equals() ©) contains() b) compareTo() 4) coneat() 22. What will be the output of the following code? public class Main{ public static void main(String [Jargs){ String str = "Tava String str2 = "Tava", String str3 =new String(“Java"); Systemout-printIn(strlequals(stt2) && strl.equals(str3)); } 1 a) true ©) Compile error b) fae 4) Runtime error 23. What will be the output of the following code? public class Main{ public static void main(String [Jargs){ String. str] = "Java"; String str2 = "Java"; Systemout printIn(strl toUpperCase()); Systemout-printin(strl); System.out println(str2=str2.toUpperCase()); Systemout.printin(str2); 1 } a) JAVA JAVA LEARN LEARN b) JAVA Java LEARN LEARN ©) JAVA JAVA LEARN Lea 2023-24/Grade- X /Slip Test 3/Computer Application Page 5 of 9 24, Java Array can allocate a) Dynamic Memory ©) Both A and B b) Static Memory 4) Runtime allocation of memory 25. Which of the following is used to declare,construct, and initlaize an array? a) int arr (] b) int (] arr = (1, 2, 3); ) int [J arr= {{1}.12}}5 ) int arr (}E) = (41, 23,43} }5 26. In java, array elements are stored in memory locations, ACL, 2,3, 4}; a) Random ¢) Sequential & Random. b) Sequential ¢) Binary search 27. What does the following method do? public static void numbers (int [ ] num) { for(int x= 1;x brown? Fox< jumped\ over? the: “lazy/ dog, Sample output: dog lazy the over jumped for brown quick (6. Program to print words whose first character of the word is uppercase and last character of the word is lowercase. Sample input 1 Enter the sentence: Quick brown fox Jumped over the Lazy dog Sample output: Words whose first letter is uppercase and last letter is lowercase: Quick Jumped Lazy Sample input 2: Enter the sentence: The capital of India is New Delhi 2023-24/Grade- X /Slip Test 3/Computer Application Page 8 of 9 Words whose first letter is uppercase and last letter is lowercase: The India New Delhi Q7. Write a program to input integer elements into an array of size 20 and perform the following ‘operations: () Display largest number from the array. (ii) Display smallest number from the array. (ii) Display sum of all the elements of the array. Q8. Write a program to accept the names of 10 cities in a singke dimensional string array and their STD codes in another single dimensional integer array. Search for a name of a city input by the user in the list. If found, display "search successful” and STD of the city else "search unsuccessful”. Make use of binary search. Also sort the array in descending order of the STD codes and display the sorted array ie STD code and city name 2023-24/Grade- X /Slip Test 3/Computer Application Page 9 of 9

You might also like