ICSE Computer Applications Class 10 - KnowledgeBoat

1y ago
790 Views
30 Downloads
609.01 KB
18 Pages
Last View : Today
Last Download : 1m ago
Upload by : Shaun Edmunds
Transcription

ICSE Computer Applications Class 10These questions will help you revise for Section A of Computer Applications Class 10 board examination. Solutions are provided after thequestions.Answer the following questions1. Name the four basic principles of Object Oriented Programming2. Define the following:i) Abstractionii) Encapsulation3.4.5.6.7.8.9.10.11.12.13.14.15.What are constants in Java? Give an example.Name the wrapper classes of char type and boolean type.Why an object is called an instance of a class? Explain.Name the two types of constructors.State the method that:i) Converts a String to primitive float type.ii) Determines if the specified character is an uppercase character.How is implicit conversion different from explicit conversion? Give an example.How are private members of a class different from public members?What are the two ways of invoking methods?List out the access specifiers in java?Explain the terms operator precedence and associativity.Name the package that contains:i) Scanner classii) String className the type of error (syntax, runtime or logical error) in each case given below:i) Math.sqrt(25 - 50)ii) double x;y;z;Differentiate between the followingi) System.exit(0) and breakii) Null loop and an infinite loop.iii) break and continueiv) Boxing-Unboxingv) Searching and Sortingvi) while loop and do-while loopvii) Single Dimensional Array and Double Dimensional Arrayviii) length and length()ix) Linear search and Binary searchx) Subscript and subscripted variablexi) Constructor and Methodxii) next() and nextLine()xiii) and equals()xiv) Syntax Error and Logical Errorxv) Primitive Data Types and Composite Data TypesPage 1/18 w w w.know ledgeboat.com

Evaluate the given expressions:Question 1int a 4, b 2, c 8;i) a b * c %aii) a b / c aiii) a % b b % c b / a c / biv) c a - b a - cQuestion 2int m 100, n 200, p 500;i) m n n - pii) m p % m n - 100iii) !(m * 2 n)iv) m n && p % m 0v) n % m ! p % pDetermine the output of the following statements1. System.out.println (1 2*5%3);2. System.out.println (1.5 2*'b');3. char ch 'X';System.out.println(ch 5);System.out.println(--ch);4. System.out.println(Math.pow (25,0.5));5. System.out.println (Math.max('C','G'));6. System.out.println ("ABCD" 10 10.5);7. int m 2, n 10;System.out.println(m * 2 n);System.out.println(!(m n && n m));8. System.out.println("L APTOP".charAt(0) "LENOVO".charAt(1));9. harAt(3)));10. e how many times the following loops gets executed and write the outputQuestion 1int x 100;while (x! 0){System.out.println(x);if (x % 6 0)break;x--;}Question 2int m 2, n 5;while (m n){System.out.println(m " " n);m ; n ;}Question 3int i 0;while ( i 10){if (i % 2 0)continue;System.out.println(i);}Page 2/18 w w w.know ledgeboat.com

Question 4int i;for (i 50; i 10; i - 10)System.out.println(i);System.out.println( i*10);Question 5for (int i 3; i 1; i--){for (int j i; j 1; e the OutputQuestion 1String s1 "BASIC", s2 "BASE";System.out.println(s1.length() s2.length());System.out.println(s1.charAt(0) th() - 0,2));System.out.println(s1.concat("" ;System.out.println (s2.substring(2, rAt(s1.length() - 1), 'L'));Question 2int arr[] {12, 10, 5, 8, 7};System.out.println(arr.length arr[arr.length - 1]);System.out.println(arr[0] --arr[2] * arr[4]);for (int i 0; i arr.length; i )System.out.print(arr[i] " ");System.out.println("\n is the output");Question 3char x[] {65, 66, 67, 68, 32}; //Note: 32 is the ASCII of space charSystem.out.println(x[0] " " x[3]);System.out.println( x[1]);System.out.println(x[1]);for (int i 0; i x.length; i )System.out.println(x[i]);Question 4String st[] {"MARS", "EARTH", "MOON", t.println(st[0].length() S'));System.out.println(st[3].charAt(0) ) "" ) st[2].charAt(0));System.out.println(st[2].length() st[3].length());Question 5double x[] {1, 2, 3, 4.56}; int a le.toString(x[2] x[1]));System.out.println(x[0] x[1] * x[2]);System.out.println( x[ a]);Question 6String s "Examination";int a 20, b 19;System.out.println(s a b);System.out.println(a b s);System.out.println('A' 'B' " is the Output");System.out.println("Output is " 'A' 'B');System.out.println("Output is " ('A' 'B'));System.out.println("Output is " a*b%2);System.out.println("Output is " 'a' 5);System.out.println('a' 5 " Output");Page 3/18 w w w.know ledgeboat.com

Rewrite as directedQuestion 1Using single if statement:if (code 'G')System.out.println("Green");if (code 'g')System.out.println("Green");Question 2Using while loop:for (int x 1, y 2; x 5 && y 6; x , y )System.out.println(x "\n" y);Question 3Using do.while loop:for (int a 125; a 0; a a / 10){System.out.println(a % 10);}Question 4Using ternary operator:if (a % 2 n("ODD");Question 5Using nested if statement:if (a 10 && a 20)System.out.println("Number in range");elseSystem.out.println("Number not in range");Page 4/18 w w w.know ledgeboat.com

SolutionsAnswer the following questionsQuestion 1Name the four basic principles of Object Oriented ymorphismQuestion 2Define the following:i) AbstractionAbstraction refers to the act of representing essential features without including the background details or explanations.ii) EncapsulationWrapping of data and functions that operate on that data into a single unit is called Encapsulation.Question 3What are constants in Java? Give an example.A variable whose value cannot change once it is assigned is termed as Constant. In Java, we declare a constant by using thekeyword 'final' as shown in the below example:final int DAYS IN A WEEK 7;Question 4Name the wrapper classes of char type and boolean type.The wrapper class of char is Character and boolean is Boolean.Question 5Why an object is called an instance of a class? Explain.A class can create objects of itself with different characteristics and common behaviour. So, we can say that an Object represents aspecific state of the class. For these reasons, an Object is called an Instance of a Class.Question 6Name the two types of constructors.Two types of constructors are Parameterised constructors and Non-Parameterised constructors.Question 7State the method that:i) Converts a String to primitive float type.Float.parseFloat()ii) Determines if the specified character is an uppercase character.Character.isUpperCase()Question 8How is implicit conversion different from explicit conversion? Give an example.In an implicit conversion, the result of a mixed mode expression is obtained in the higher most data type of the variables withoutany inter vention by the user. For example:int a 10;float b 25.5f, c;c a b;Page 5/18 w w w.know ledgeboat.com

In case of explicit type conversion, the data gets conver ted to a type as specified by the programmer. For example:int a 10;double b 25.5;float c (float)(a b);Question 9How are private members of a class different from public members?Private membersPublic membersThey are accessible only within the class in which they are declared.They are accessible both within and outside their class.They are not inherited by derived classThey are inherited by derived classQuestion 10What are the two ways of invoking methods?Two ways of invoking methods are:1. Pass by value.2. Pass by reference.Question 11List out the access specifiers in java?1. private — private members are accessible only inside their own class.2. protected — protected members are accessible inside their own class, classes within the package and subclasses.3. public — public members are accessible in all the classes.Question 12Explain the terms operator precedence and associativity.Operator precedence specifies the order in which the operators in an expression are evaluated when the expression has severaloperators.When an expression has two operators with the same precedence, the expression is evaluated according to its associativity.Associativity of an operator can be either right-to-left or left-to-right.Question 13Name the package that contains:i) Scanner classjava.utilii) String classjava.langQuestion 14Name the type of error (syntax, runtime or logical error) in each case given below:i) Math.sqrt(25 - 50)Runtime Errorii) double x;y;z;Syntax ErrorPage 6/18 w w w.know ledgeboat.com

Question 15Differentiate between the followingi) System.exit(0) and breakSystem.exit(0)breakIt is a method of System classIt is a Java language statementIt terminates the programIt terminates the loop or the switch block inside which it is placed.ii) Null loop and an infinite loop.Null loopInfinite loopIt has an empty bodyIt may or may not have an empty bodyIt iterates for a finite number of iterationsIt continues iterating indefinitelyExample:int i 0;while( i 10);Example:int i 0;while(i 10)System.out.println("Infinite Loop");iii) break and continuebreakcontinueIt is used to unconditionally jumpout of the loopIt is used to unconditionally jump to the next iteration of the loop, skipping the remainingstatements of the current iteration.It is used in switch-case and loopsIt is only used in loops.iv) Boxing-UnboxingBoxing is the conversion of primitive data type into an object of its corresponding wrapper class. Unboxing is the opposite ofBoxing, it is the conversion of wrapper class object into its corresponding primitive data type. Below program highlights thedifference between the two:public class Boxing {public static void main(String args[]) {int a 100, b;//BoxingInteger aWrapped new Integer(a);//Unboxingb aWrapped;System.out.println("Boxed Value: " aWrapped);System.out.println("Unboxed Value: " b);}}v) Searching and SortingSortingSearchingSorting means to arrange the elements of the array in ascending ordescending order.Searching means to search for a term or value in an array.Bubble sort and Selection sort are examples of sorting techniques.Linear search and Binary search are examples of searchtechniques.Page 7/18 w w w.know ledgeboat.com

vi) while loop and do-while loopwhiledo-whileIt is an entry-controlled loop.It is an exit-controlled loop.It is helpful in situations where numbers of iterations are not known.It is suitable when we need to display a menu to the user.vii) Single Dimensional Array and Double Dimensional ArraySingle Dimensional ArrayDouble Dimensional ArrayIt contains single row and multiple columns.It contains multiple rows and multiple columns.It needs a single subscript to access its elements.It needs two subscripts to access its elements.viii) length and length()lengthlength()length is an attribute i.e. a data member of array.length() is a member method of String class.It gives the length of an array i.e. the number of elements stored in an array.It gives the number of characters present in a string.ix) Linear search and Binary searchLinear SearchBinary SearchLinear search works on sorted and unsorted arraysBinary search works on only sorted arrays (ascending ordescending)Each element of the array is checked against the target value untilthe element is found or end of the array is reachedArray is successively divided into 2 halves and the target element issearched either in the first half or in the second halfLinear Search is slowerBinary Search is fasterx) Subscript and subscripted variableSubscript is the index of the element in the array whereas Subscripted variable is the name of the array when it is used with asubscript to access a single element of the array.Page 8/18 w w w.know ledgeboat.com

xi) Constructor and MethodConstructorMethodIt is a block of code that initializes a newly createdobject.It is a group of statements that can be called at any point in the program using itsname to perform a specific task.It has the same name as class name.It should have a different name than class name.It has no return typeIt needs a valid return type if it returns a value otherwise voidIt is called implicitly at the time of object creationIt is called explicitly by the programmer by making a method callIf a constructor is not present, a defaultconstructor is provided by JavaIn case of a method, no default method is provided.It is not inherited by subclasses.It may or may not be inherited depending upon its access specifier.xii) next() and nextLine()next()nextLine()It reads the input only till the space so it can read only asingle word.It reads the input till the end of line so it can read a full sentenceincluding spaces.It places the cursor in the same line after reading the input.It places the cursor in the next line after reading the input.xiii) and equals()equals() It is a methodIt is a relational operatorIt is used to check if the contents of two strings are same or notIt is used to check if two variables refer to the same object in memoryExample:String s1 new String("hello");String s2 new String("hello");boolean res ng s1 new String("hello");String s2 new String("hello");boolean res s1 s2;System.out.println(res);The output of this code snippet is true as contents of s1 and s2are the same.The output of this code snippet is false as s1 and s2 point to differentString objects.xiv) Syntax Error and Logical ErrorSyntax ErrorLogical ErrorSyntax Errors occur when we violate the rules of writing the statements ofthe programming language.Logical Errors occur due to our mistakes in programminglogic.Program fails to compile and execute.Program compiles and executes but doesn't give thedesired output.Syntax Errors are caught by the compiler.Logical errors need to be found and corrected by peopleworking on the program.Page 9/18 w w w.know ledgeboat.com

xv) Primitive Data Types and Composite Data TypesPrimitive Data TypesComposite Data TypesPrimitive Data Types are Java's fundamental data typesComposite Data Types are created by using PrimitiveData TypesPrimitive Data Types are built-in data types defined by Java languagespecificationComposite Data Types are defined by the programmerExamples of Primitive Data Types are byte, short, int, long, float, double, char,booleanExamples of Composite Data Types are Class and ArrayEvaluate the given expressions:Question 1int a 4, b 2, c 8;i) a b * c % aa b*c%a 4 2*8%4 4 0 4ii) a b / c aa b/c a 4 2/8 4 4 0 4 8iii) a % b b % c b / a c / ba%b b%c b/a c/b 4 % 2 2 % 8 2 / 4 8 / 2 0 2 0 4 6iv) c a - b a - cc c (a - b a - c) c 8 (4 - 3 5 - 8) c 8 (-2) c 8-2 c 6Question 2int m 100, n 200, p 500;i) m n n - p100 200 200 - 500 300 -300 trueii) m p % m n - 100100 500 % 100 200 - 100 100 0 100 100 100 truePage 10/18 w w w.know ledgeboat.com

iii) !(m * 2 n)!(100 * 2 200) !(200 200) !(true) falseiv) m n && p % m 0100 200 && 500 % 100 0 true && true truev) n % m ! p % p200 % 100 ! 500 % 500 0 ! 0 falseDetermine the output of the following statementsQuestion 1System.out.println (1 2*5%3);Output2Explanation1 2*5%3 1 10 % 3 1 1 2Question 2System.out.println (1.5 2*'b');Output197.5Explanation1.5 2 * 'b' 1.5 2 * 98 (ASCII Code of 'b' is 98) 1.5 196 197.5Question 3char ch 'X';System.out.println(ch 5);System.out.println(--ch);Output93XPage 11/18 w w w.know ledgeboat.com

Explanationch 5 88 5 (ch will be conver ted to int due to implicit casting) 93ch is 'Y' due to ch in the previous statement. --ch will first decrement ch to 'X' and then print it.Question 4System.out.println(Math.pow (25,0.5));Output5ExplanationMath.pow(25,0.5) means 25 5Question 5System.out.println (Math.max('C','G'));Output71ExplanationAs return type of Math.max is int so 'G' will be conver ted to its ASCII code which is 71.Question 6System.out.println ("ABCD" 10 10.5);OutputABCD1010.5ExplanationAs "ABCD" is String so implicit type conversion will conver t 10 and 10.5 also to String and add it to the end of "ABCD".Question 7int m 2, n 10;System.out.println(m * 2 n);System.out.println(!(m n && n m));OutputfalsefalseExplanationm * 2 2 * 2 4. Som n && n m is true soPage 12/18m * 2 nis false.becomes false.!(m n && n m) w w w.know ledgeboat.com

Question 8System.out.println("L APTOP".charAt(0) harAt(0) "LENOVO".charAt(1) 'L' 'E'.As we are tr ying to add two char type values, both will be conver ted to their respective ASCII codes and the output will be the sumof their ASCII codes as an int value.'L' 'E' 76 69 145Question es 'c'.returns 'C'.Character.toUpperCase('c')Question uttrueExplanationAs 'j' is a letter soCharacter.isLetter('j')returns true.Analyze how many times the following loops gets executed and write the outputQuestion 1int x 100;while (x! 0){System.out.println(x);if (x % 6 0)break;x--;}Output10099989796ExplanationLoop executes 5 times.When x becomes 96, x % 6 is 0 so break statement is executed and loop exits.Page 13/18 w w w.know ledgeboat.com

Question 2int m 2, n 5;while (m n){System.out.println(m " " n);m ; n ;}Output23.56.ExplanationInfinite loop as m and n both are incremented by 1 so m n is always true.Question 3int i 0;while ( i 10){if (i % 2 nationLoop executes 10 times.Due to the if check, for even numbers continue statement gets executed because of which println is skipped.Question 4int i;for (i 50; i 10; i - 10)System.out.println(i);System.out.println( i*10);Output504030201010ExplanationLoop executes 5 times.As there are no curly brackets in the for loop so only System.out.println(i); is in the loop body. It gets executed 5 times. Asdecremented by 10 in each iteration, when the loop exits, the value of i is 0. So, i*10 1 * 10 10.iisQuestion 5for (int i 3; i 1; i--){for (int j i; j 1; j--)System.out.print(j);System.out.println();}Page 14/18 w w w.know ledgeboat.com

Output321211ExplanationOuter loop executes 3 times, inner loop executes 6 arks1 st Iteration of outer loop2 nd Iteration of outer loop3 rd Iteration of outer loopWrite the OutputQuestion 1String s1 "BASIC", s2 "BASE";System.out.println(s1.length() s2.length());System.out.println(s1.charAt(0) th() - 0,2));System.out.println(s1.concat("" ;System.out.println (s2.substring(2, rAt(s1.length() - 1), on 2int arr[] {12, 10, 5, 8, 7};System.out.println(arr.length arr[arr.length - 1]);System.out.println(arr[0] --arr[2] * arr[4]);for (int i 0; i arr.length; i )System.out.print(arr[i] " ");System.out.println("\n is the output");Page 15/18 w w w.know ledgeboat.com

Output124013 10 4 8 7is the outputQ

ICSE Computer Applications Class 10 These questions will help you revise for Section A of Computer Applications Class 10 board examination. Solutions are provided after the questions. Answer the following questions 1. Name the four basic principles of Object Oriented Programming 2.