Download as pdf
Download as pdf
You are on page 1of 33
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING CONCEPTS . Java is a high level language. . IDK means Java Development Kit, . Java does not support overloading. . There are no pointers in Java. . Java files are saved with ,java extension. A class in Java is saved with CLA extension, . Comments and indentation make the program more readable. . A program written in Java is portable and reusable. . There may be three types of errors in a program; syntax error, logical error and runtime error. 10. Logical errors are the most difficult errors to locate. 11, Removing errors from a program is called debugging. 12. A program with syntax errors cannot compile. 13. A program with logical errors can compile but will give wrong output. 14, A program with runtime errors can compile but it will not execute. 15. A Java program must have a main method. 16. Every statement in Java terminates with a semicolon(;).. 17. A program always starts with a class name. 18. The name of the class is followed by the keyword class. 19. A program can have more than one class. 20. A program can have several methods. 21. Command to compile a Java program is javac. 22. Command to execute a compiled Java program is java. 23, Comments can be in a single line or multiple lines. 24, A class is called a collection of objects. 25. A class is also called a factory of objects. 26. Wrapping of data and methods in a single unit is called encapsulation. 27. A module is a small program in itself which can be tested and can do a specified task. 28. An attribute is a type of information that a Java class consists. 29. An attribute determines the qualities of the objects belonging to a particular class. PPI aweene 30. An object is an instance of a class. ICSE 100% SUCCESS IN COMPUTER APPLICATIONS - 10 Multiple Choice Questions 1, Which is not a feature of Object-Oriented Programming? a @ Duplicate/Redundant da, (@ Efficient Code (® Code reusability (© Modula! ability? (a) Inberitance Which feature of the OOP indicates code reus (@ Abstraction () Polymorphism . One object can interact with another object through -. 2 (@) Message reading _(b) Message passing () Data transfer 4, Which statement is true about Java? (a) Java is a middle level programming language (@) Java is a code dependent programming languabe (Encapsulation x (@ Data binding (©) Java is a platform-independent programming Tanguage (@ Java is a platform-dependent programming langua8e > 5. Which of the following component of Java, is used to compile, debug and ane be eee programs? @ AWT @® mT (Q DK 6. Which of the following is a programming error? (@ Runtime error (©) Logical error (c) Syntax error (@ Allof these 7. Which of the following errors is difficult to locate? (@ Runtime error @® Logical error (© Syntax error’ @ Allof these 8, Errors which occur due to breaking of grammatical rule are called. (@) Runtime error (b) Logical error (©) Syntax error (@ All of these |. A program with logical error ... (@ can compile and run (c) can compile but cannot run 10. You have divided a number by zero. It will produce....-..-- @ Runtime error @ Logical error (© Syntax error @ Allof these 11. What is the term related with creation of an object ? (@ Inheritance (®) Factory (©) Instantiation @ Initialization 12. You have used wrong punctuation in the program. It will produce... e (©) cannot compile but run (@ show a syntax error (@ Runtime error () Logical error (© Syubicector 13, You are trying to find square root of a negative number. The program will ae lof tier (@) Runtime error () Logical error (© Syntix error Produce........... 14. Find the odd term. @ Allof these @ Java (6) Greenfoot (©) Blue 15, When you compile a program, which of the following file is not created? @ Notepad (@ class () ctxt Ge ae lone of these Answers 1. @ 2. @ 3. (b) 4. © 5. (c) & @ 4 7. ®) 8. 9. @ 10. (@) ul. (© 2 © B.@ (@ 4 @ : 18. @ VALUES, DATA TYPES AND VARIABLES 1, There are 8 primitive data types in Java. 2. Aconstant does not change its value in the entire program. 3. A constant is also called a literal. 4, In-built data types are called primitive data types. 5. Byte, short, long, int, float, double, char and boolean are primitive data types. 6. Array is non-primitive data type. 7. Class is a non-primitive data type. 8. Range of short data type is -32768 to +32767 9. A number having integer and fractional part is called a floating point number. 10, The precision (decimal size) of float data type is 7 digits. 11, The precision of double data type is 15 digits. 12, String value is enclosed in double quotes. 13. Character value is enclosed in single quotes. 5 14, Unicode is the name given to character set of Java. 15, A variable is a value that can change in a program. 16. Local variable is available only in a part of the program and its scope is local. 17. Global variable is available to the entire program and its scope is global. 18. The default value for string is null. 19, The default value for double type is 0.0.4. 20. The default value for boolean is false. 21. The default value for char is "\u0000'. 22. The default values for byte, short and int are 0. (without decimal). 23, The default value for long is OL. 24, The default value for float is 0.0f. 25. Size of int data type is 4 bytes. 26. Size of byte data type is 1 byte. 27. Size of short data type is 2 bytes. 28. Size of long and double data type is 8 bytes each. 29. Size of char data type is 2 bytes. 30. Size of boolean data type is 1 byte. \ 31. Size of float data type is 4 bytes. {CSE 100% SUCCESS IN COMPUTER APPLICATIONS - 10 10. 11. 12. 13. 14, 15. 16. tive data types are there in Java? . How many pri @s 3 @4 What is the numerical range of a char data type in Java? (a) 00 256 (@®) 128 to 127 (0) 010 65535 What is the range of short data type in Java? (a) -128 to 127 (0) 32768 t0 32767 (©) -2147483648 to 2147483647 (d@) None of these . What is the range of byte data type in Java? @ -128 to 127 (b) -32768 10 32767 (©) -2147483648 to 2147483647 (@ None of these ‘The size of the char data type i (@ 1bit ©) 7 bits (©) 1 byte 0 is not the default value of which data type ? (@ double (b) byte (©) short . In Java size of int data type is... (©) 8 bytes (@ 2 bytes (b) 4 bytes Which of the following is false? . (@ doubled =7.5d; (b) double d = 7.5D; ‘The default value for all referenced data types? (© double d = 7.5F; @8 (@ 0 to 32767 @ 2 bytes (@ long (@ None of these (d@) None of these (@ 0 © 0.0 (© null @ false Which is the smallest integer data type? (@ Int @ Byte (©) Short @ long Which of the following data typés goes through floating data types? @ int ©) byte (© long @ double Character data type cannot store ..- value. (a) Special Character (b) Digit (© String @ Letter Which of these coding types is used for data type characters in Java? @ Asc (® ISO-LATIN-1 © Unicode (@ None of these Which of these values can a boolean variable contain? (a) True and False () 0&1 (©) Any integer value @ tne ‘The operator & can return ... value. @ a @®) Boolean : (©) Character (@) Integer or Boolean Literals in Java must be appended by which of these letters? @L (b)1 @pD @ L and 1 (upper or lower case) ~ -mnns-t ICSE tnt chinnna 17 Literal can be of which of these data types? (a) integer (8) float (©) boolean (d) All of these 18, Which of these cannot be used for a variable name in Java? (@) identifier (©) keyword (©) identifier and keyword (d) None of these 19, The default value for short data type is ... . @ 0.0 (b) 0.01 @o @1 20. The real number (float number) can take how many decimal numbers? @ 15 ® 10 7 @ 14 21, The number 12.123456789 will be stored With ......... data type. @ float (©) long (©) double @ int Answers 1@ . 2© 3. @) 4. @ 5. 6. (a) 71.0 8. @ 9.0 10. @ 1 @ 2 © B© 4@ 15. @ 16. @ 1@ B® 026 20. © 21. TOES To Note . An operator is a symbol which represents and action oF P 2. An operand is an object which is capable of being manipulation. ; ' f a ne tions can be mathematical, relational 3. Operators are used for performing various operations. The operal logical. 4, Operators in Java can be classified into 6 types: * Arithmetic Operators * Relational Operators yrocess. Assignment Operators © Logical Operators # Bitwise Operators * Unary Operators Arithmetic operators are used to perform arithmetic operations on variables and data. . Arithmetic operators are: * + Addition * * Multiplication */ Division © % Modulus (Remainder) | There are three types of operators in Java based on the number of operands. They are: Unary operator, Binary operator and Ternary operator 8. An operator that acts on a single operand is called unary operator. It uses a single variable. 9. An operator that acts on two operands is called binary operator. Jt uses two variables. 10. An operator that acts on three operands is called ternary operator. It uses three variables. 11. +, -, ++, -- are unary operators. 12. In ++a, ++ is a prefix increment operator. 13. Inat++, ++ is a postfix increment operator. aw Subtraction _ is a prefix decrement operator. is a postfix decrement operator. 16. Ina prefix increment or decrement operator, the rule of evaluation irst change the value and then Us 17, Ina post increment or decrement operator, the rule of evaluation is: First use the value and then char 18, Assignment operators are uséd in Java to assign values to variables, 19, Assignment operators are: =, +=,-=, *=,/=, %=. 20. Relational operators are used to check the relationship between two operands. VIE, >y <, >=, <= are the six relational operators in Java, ‘ 22. Logical operators are used to check whether an expression is true or false. 23, AND, OR, NOT are the three logical operators in Java. ; . The AND operator is represented by &&. ICSE 100% stinncos 5. The OR operator is represented by ||. 5. The NOT operator is represented by |. . Bitwise operators in Java are used to perform operations on individual bits. . The ternary operator (conditional operator) is shorthand for the if-then-else statement. ). The syntax for ternary operator is : . An expression in Java is a combination of operators and operands that is used to perform mathematical or . Ifa keyword is used as an operator, it is called named operator. The named operator is instanceof. . The order.of evaluation in which operators are evaluated is called precedence of operators. . Parenthesis have the highest order of evaluation. variable = Expression ? expression| : expression? logical calculations. 1 Choice Questions There are arithmetic operators in Java. @4 6 os 3 . Which of the following can be operands of arithmetic operators? @ Numeric (® Boolean (©) Characters @ Both Numeric and Characters . Modulus operator, %, can be applied to which of the following data type? (a) Integers (©) Floating-point numbers) (© Both Integers and floating-point numbers (qd) None of these With a = 0, which of the following are legal lines of Java code for changing the value of a to 1? Lo att; Dasath 3.at=1; 4.astl; @ 1,2and 3 (®) 1and 4 (© 1,2, 3 and4 (@ 3and2 . Decrement operator, ——, decreases the value of variable by 10, ML. @o 1 3 @4 . Which of these has highest precedence? @O ® ++ @* @ >> /. Which of these has lowest precedence? (@ Logical operator ~ (6) Relational operator (c) Assignment operator (d) Postfix operator . What is the order of precedence (highest to lowest) of following operators? 1. && 211 3% @ 1->2->3 @2->1->3 (3->2->1 (@2->3->1 1. What is the output of relational operators? (@ Integer (6) Boolean (©) Characters @ Double ‘What is the input for logical operators? @ 1and0 (6) true / false (©) char / String (@) None of these What is the output of any Logical operation in Java? (@) lord (&) true or false (© char or String (@ None of these an ash nd? . 12. Which of the following operators works with a single opera! val Exclusive OR (d) Logical NOT (@ Logical AND (b) Logical OR (0) Logica © yerator in Java! 13. Which among the following is a Logical Unary NOT oP @* @ ~ o! @# 14, What is the output of the following Java code? boolean b = true; b= Ib; System. out. printin((b); (@ te © false (© Compiler ertor es oF these 15. What is the output of a Logical OR (||) operation if one of the inputs/operan None a (a) false (b) true (o) true or false nat ne e 16. What is the output of Logical AND (&&) operation if one of the inputs/operands is false? . (@) false (b) true (©) true or false @ None of these 17. What is the output of a Logical OR (||) operation if one of the inputs/operands is true? (@) false © true (¢) true or false @ None of these 18. What is the output of a Logical AND (&&) operation if both inputs/operands are true? (a) false (b) true (©) true or false @ None of these 19. Ternary operator is .. (a) Relational Operator (0) Conditional Operator(¢) Logical Operator 20. Ternary operator can be used in place of (a) if-else statements (6) while, do while loops (©) for loop (@ None of these @ Alll of these 21. Java W/O is used to process .... (@ input (&) output (© Both a and b @ None of these 22. Which of the following classes is used by Byte streams for input and output operation? (@ InputStream (&) InputOutputStream (c) Reader (d) All of these 23, Which of these class contains the methods print( ) and printin( )? (@ System ®& System.out (©) BufferedOutputStream (d) PrintStream Anawerr L© 2.@ 3. © 4. © 5.) 6. @ 1.0 8 @ 9. @) 10.) UL. ®) 2 @ 13.@) 14. ®) 15. (b) 16. @ 17. @) 18. @) 19. (b) 20. @) 21. (©) 2 © 2B. @ IRE snes asa na WS Se . Conditional statements are mostly used in decision-making. These statements take a decision on the basis of . The conditional statements are also referred as branching statements because the program takes a decision . Java provides three types of conditionals : ). The break statement is used to terminate the loop. . A switch statement can have true or false status. . Compound statement is enclosed between the pair of braces { and }. . Flow chart is a diagrammatic representation of algorithm. . Removing the syntax, _ Use of goto statement reates an unconditional jump within program. . Control structure |. Break statement i CONDITIONAL CONSTRUCTS IN JAVA ——_—_—_—_—_—_——— some conditions. based on the result of the assessed condition. if, if else, if else if Use if to specify a block of code to be executed, if a specified condition is tue. Use else to specify a block of code to be executed, if the same condition is false. Use else if to specify a new condition to test, if the first condition is false. A conditional statement begins with the keyword if followed by parentheses. ‘An expression is placed inside the parentheses, which is evaluated when the conditional statement is reached. The result of the evaluation is a boolean value. ‘A code block refers to a section enclosed by a pair of curly brackets. 2 The break statement can be used with all types of loops. Semicolon is not allowed with a switch statement. Computer program is a sequence of instructions to perform a specific task. Algorithm is step-by-step instructions written in logical sequence. Pseudo codes are similar to program codes without the syntax of a language. semantic and logical errors in a program is called debugging. ‘The statement within the block is executed one afier the other. This type of structure is called sequential structure. is used to transfer the control to the other part of the program depending on some conditions. Java offers three selection statements ; if, if-else and switch. While if statement checks only for the condition that evaluates true, if-else structure checks for both truth and falsity of a condition. tructure in Java consists of series of case keyword. The switch st Each of the case value must be a unique literal constant and not a variable. is used to skip out of switch structure. Switch structure is an efficient way of writing multiple if statements that contains only equality conditions of integral values. J _asemieern ADDI IPATIONS - 10 63 M. Choice Questions 1. An if statement is a... (@) toop (®) conditional 2. An ifeelse statement is also called..... stock statements (@ Branching statement (b) Control statement oO ;, branching. 3, Anifor else ifstatement accepts. a8 input before (0) float (A) execution (o) iteration (@ Alllof these (@) char (@ boolean ©) im AA 4, An else statement should be preceded by _ statement in (a None ofthese or © elseif (9 ifor ese f the following is correct? (b) else block is executed (a both if and else blocks are executed .. control statement. 5. If the condition of an if statement is false, which of (@) if block is executed (©) both if and else blocks are skipped 6. A switch case statement in Java is a (@ selection @ iteration (b) loop © jump 7. Which of the following is an alternative to switch in Java? ; (@ break, continue (6) for, while © if else @ goto, exit 8. What are the keywords used to implement a switch case in Java? (a) switch, case (b) default (©) break (@ All of these 9. What are the parts of a switch in Java? (a) switch input condition (b) case constants (©) case statements (@ All of these 10. If the condition of an IF-statement is false, which is true below. (@ If block is executed © else block is executed (©) Both if and else blocks are skipped (@ Both if and else blocks are executed 11. What is maximum lines of code that can be written inside an if, else or if else block? @2 (®) 32 (©) 512 12. What is true about a break? (@) None of these (@) break stops the execution of entire program (©) break stops the execution and forces the control out ofthe loop (©) break forces the control out ofthe loop and stars the execution of next iterat (d) break stops the execution of the loop for certain time frame msisoeny 13, Which of the following is used with the switch statement? @ continue (&) exit (©) break 14, Which of the following is not a decision-making statement? O82 @r © ifelse (© smten 15. The break statement in switch ca: (a) prevents from fall-through mn (©) both (a) and (6) ) causes an exit from j @ do-while ICSE 44 : S0% SUCCESS In ComPUTER APPLICA 1. ® 2. @ * 3, .@ 06 wu @ 40 50 6@ 710 £&@ 1% @ 2H BO L : -@ 4. (d) 15. 0 16. ® JR APPLICATIONS - 10. ICSE 100% SUCCESS IN COMPUTE . When the statements are repeated sequentially a numb . There are three types of loops in Java; for, while and do while. 3. An entry-controlled loop checks the condition at the time of entering ITERATIVE CONSTRUCT SS the construct is known er of times in a program, loop. the body of loop. If the condition is tru the program control enters the body of the loop. 4. The for loop is known as entry-controlled loop. au on 2 M. s . The while is also known as entry-controlled loop. . An exit-controlled loop checks the condition after executing the body of | loop. If the condition is true, the loo will perform the next iteration otherwise program control will move out of the loop. |. The do-while loop is called an exit-controlled loop. . The do-while loop executes at least once, if the condition is false. ‘The while loop checks the condition first before its execution. |. When the condition is never met in the loop, the loop is called infinite loop. . The break statement is used to unconditionally jump out of the loop. . The continue statement is used to unconditionally jump to the next iteration of the loop, skipping the remaining statements of the current iteration, . The while and do while loops are used when the number of iterations is not known in advance. |. The for loop is used when the number of iterations is known. Choice Questions . Which of the following is not a decision-making statement? @ if © ifelse (© switch ; 7 | @ do-while . Which type of the loops is best known for its boolean condition that controls entry to the loop? (@) do-while loop ® for (©) for-each @ whil " . Which of the following loops is known for using an index or counter? a (@) do-while loop ©) for (©) for-each ( f . Which loops executes the body of the loop at least once? Oma @ do-while loop (®) for (©) for-each e . When the number of iterations is finite, you will use .......loop, an (@ do-while loop (6) for © while (@) Mixed loop TSE tnnar orn 16. iteration of that loop? (@ break (®) continue (©) stop (d) skip Aw -loop statement repeatedly executes a target statement as long as a given condition is tue. (@) for (6) while (©) do-while (d) nested ifs What is the syntax of a continue is a single statement inside any loop? (a) jump; (®) continue; (©) start; (@) run; Which is not a valid loop name? @) for (©) while (©) do while @) ternary operator ). A break statement inside a loop causes the program execution .....the loop. @ exit (®) continuation with next iteration () never exit @ stop . Which of the following loops is most suitable for collection types of data like array? (@) for (6) while (©) do while (@ ternary operator . A break statement can be used to terminate a case in the switch statement? (@) True (b) False (©) It works like an infinite loop (@ It does not work . What is the output of the following code? int i = 0; for(i = 0; i < 3;i++) { } System.out.printin(i); @ 3 ®o0 ©2 @ Compilation Error |. What is the output of the following code? inti = 0; for(i = 0; i < 5;i++) { break; } System.out.printin(i); @5 0 oO4 @ Compilation Error . What is the output of the following code? inti = for(i continue; ) a System.out.printin(i); } @s5 ! What is the output of the following code? O; i < 10;i+ +) { i<5,i++){ 0 @4 (@ Compilation Error for(int i if % 2 == 0) { continue; SE 100%, sires IN COMPUTER APPLICATIONS - 10 } System.out. printIn(i); i (d) Compilation Erro, } y 013579 : @ 246810 (13579 a 17. What is the output of the following code? fortint i = 0; i < 10; i++) { if /2 == 0) { continue; } System.out.printin(i); } Compilation Er @ 23456789 123456789 (3456789 “om “ res infinite loop? ich of the following statements causes infin . rs fori = 0; 3 t+) @ All ofthese (@) fort; ;) (b) for(i Pera a a ne 19. Which FF fa following ops aes the body of loop even when condition controlling the loop i i false? @ do-while © while (© for Oo cn 20. From which point where break statement causes an exit? (@) only from innermost loop (© terminates a program (©) from innermost loops or switches @ only from innermost switch What will be the output of the following code? do { System.out.printin("Hello, I am ICSEian"); } while (true); @) Hello, I am ICSEian (©) tre, Hello, I am ICSEian What will be the output of the following code? 21. (0) Hello, I am ICSEian, true @ Infinite times; Hello, I am ICSEian 22. 8 intx = 5; int y = 100; while(x <= y) { yaylx System.out.print(" " +y); } @ 22 204 (254 252 Anawent 1@ 22@).1°) 5 O) 4M. 5 6) 7. 8. 0) 9. 0@ i.@ 2@ 13.@) 4. 15. @ 16. © 17. @ 18. (@ 19. (a) 20. (21. @ 2. & CLASS AS THE BASIS OF ALL -COMPUTATION A class is referred to as a factory of objects. Encapsulation is defined as the wrapping up of data under a single unit. Java has three types of variables; local, instance and static. Static variable is also known as class variable. A variable declared inside the body of the method is called local variable. A variable declared inside the class but outside the body of the method, is called instance variable. A variable which is declared as static is called static variable. It cannot be local. Primitive data types are built-in data types specific to a language. Primitive data types are those data types which are not composed of other data types. 10. Composite data types are those which are composed of primitive data types 11. A composite data type is composed of various primitive data types. A class can contain various primitive data types as its data members. 12. Instance variables are declared without using keyword ‘static’. 13, Each object of the class gets its own copy of instance variables. 14. Class variables are declared using keyword ‘static’. 15, All objects of a class share the same copy of class variables. 16. Each object of the class gets its own copy of instance variables. 17. Class variables can be accessed using the class name or object. ‘When a class is declared with public access specifier it is said that the class is publicly accessible. A publicly accessible class is visible everywhere both within and outside its package. Private members of a class are accessible only within the class in which they are declared. public members of the class are accessible both within and outside their class. Me COeice Quertions 1. Which of the following may be part of a class definition ? (©) instance methods —_(c) constructors (@ Allof these Per aAwrene (@) instance variables (©) None of these .. Fepresents ai @ Aclass in entity in the real world that can be distinctly identified. (b) An object (© A method @ A data field COMPUTER APPLICATIONS - 10 = SSE 100% SUCCESS IN ore lata teld + #9 4 CoNStTUCT that detines objects OF une dai +7 @aAai ‘A method @ Aclass (© An object © 4, An object is an instance of a ; od @ data (@) program (©) class (om 5. A class object is also known 2 @ Modifier (@) Identifier () Instance variable (c) en 6. The maximum number of objects of a class can be created “ ser's choice (d) Number of variable On the u @1 2 © a declared? iS yhich they are 7. Which keyword makes class members accessible outside the class in w a i lic @) private (b) protected (©) publ . ' i tside a class: 8. Find the access specifier which prohibits a class member from being used out ee @ private (®) public (©) protected Answers L@ 2. () 3. @ 406 5. @) 6. © 7. © 8. (@) es Al) _ ely USER-DEFINED METHODS . Once defined, class can be used to create objects of that type. ile class i a ). While cs isa Beneralisation Of group of things, object is a specific individual thing of the group. . In Java it is conventional to begin Class's name with uppercase and other characters in lowercase. ‘The first Word of a variable and method names contains all lowercase leters and the first letter of subsequent words, if any, is in uppercase as in class name, ). Method contains instruction codes to perform certain task. ». Once declared and defined, a method can be called wherever required. - The return keyword causes control to transfer back to the method call. . Parameters provide values to the method for processing. . Parameters do not get the vahies until the method is called. 10. Scope of the variables is the limit within which the values of the variables are made available. 11. Local variables are declared and initialised within the body of the method are not accessible outside that method. 12, Parametric variables can be accessed from inside the method in which they are declared. However, they are initialised from outside the method, before calling the method, 13, When class is used to create objects, the variables that each of the object uses is called instance variables of that class. Pane wpen aw 14, Each object created gets its copy of instance variables. 15. The variable declared in class type contains the reference to the object. 16. In Java, new operator creates object and retums a reference to that object. 17. We can access the instance variables associated with a particular object by joining the name of the object with the name of the variable using a dot operator, for example, emp.age. 18, Functions are methods that contain codes to perform a specific task and returns values for further computation. 19, Functions may be categorized as pure and impure functions. 120, Pure functions, also called accessors, are used for getting data for an object. 21. Accessors begin with term get to indicate that they receive values. 22, Impure functions, also called mutators or updaters are used for changing the object's state. 23, Mutators usually begin with the term set to indicate that they reset the values of the object. 24. Every function has a unique signature : its name, return type and a list of parameters. 25,’ More than one function bearing same name with different parameters is called function overloading. OSE too% stuccrss IN COMPUTERAPPLICATIONS=10 m 26. 27. 28. 29. 30. 3 32. 33. variables store the values directly in the memory. erence ( alu Odject variables also called reference variables store only the Fe ‘Values are passed through arguments to the function. oe ‘When the values passed are of primitive type it is termed as P* ee. ‘When the values passed are of class type itis called pass-by-refere ie of the memory location), /-value. ry ce. - Ifa variable has no objects to refer to, it is called null referent Inaccessible objects can be garbage collected in Java. ; syword this is useq ariables, the keywo: t Function, which has its parameter variable name same as that of class ¥ specify the current instant variable. 4 1 w cd = Choice Questions ‘A method in Java is ............by default. @ private © public (©) protected {2).s9en, - A function name can begin with 1 @ an alphabet © digit (©) aspace @ symbol . A static function can access... on (@ Non-static data members (b) Static data members (© Both a and b @ None of these + The keyword used to return a value from a function is... « (@) message (©) information (© return @ returns + A method that does not return any value has a .......... return type, @ im (®) double (© float @ void A method can return ..... (@ any number of values (b) 2 values (©) only 1 value Parameters in the method definition are called ..... @ infinite values (@) actual parameters (6) formal parameters (c) informal Parameters ‘The parameters that are passed to the method when it is invoked are called ., (@ actual parameters (6) formal parameters (c) informal Parameters The method that changes the state of an object is known as’. (@ impure method © perfect method @) value parameters @ void parameters @ pure method ‘The technique in which the change in the formal arameters js + #8 soca. Pirameters is reflected in the actual parameters is kn0™ (@) call by value (©) call by argument © call by method + The technique in which the values of actual parameters copied to the fo @) call by reference (@) call by value ©) call by argument (¢) cat, bi mal parameters? * . A method with many definitions is known as mee @ call by method (@ Mixed method (©) multiple methoa oa method Ics @ overloaded method E.100% SUCCESS iy COMPUTER APPLICATIONS! 15, overvmers (@ method names can be same, but the number of parameters is also the same (p) method names can be same, but the number of parameters may be same or different (0) method names are different, but the number of parameters is same (@ variables are overloaded 14, A fonction that modifies its parameters is called. (@) Modifier (©) Impure function _(c) Pure function (@) Virtual function 15, Function prototype means. . (@) Return type of a function (®) Return value of a function (© Name of the function (@ Name, Return type and inputs of the function 16, Auser-defined function can return values. @0 @1 2 @4 11, A function defined by you can have ........Parameters. @1 2 (©) any number of parameters @3 18, Function overloading is an OOP feature, that is... « (@) inheritance © encapsulation (© polymorphism @ None of these Anowers 1.@ 2.@ 3. ® 4. © 5.@ 6. (© 7. ®) 8. (@) 9. (@) 0@ 1. @ 2@ 13.0 4 15.@ 16. (6) 1.0 18. (© meer APPLICATIONS -10 CONSTRUCTOR; A constructor is a special member function that is called automatically when an instance of a class is declare A constructor is called when an object of the class is declared. A constructor can initialise the data members of the class. A default constructor is a special member function used to initialise objects. In Java objects are created dynamically in a pool of memory called the heap. The object comes into existence only after the new operator has created it. Special variables called reference variables which are like pointers to the memory location, contains reference. to an object. ‘When new creates the object from the specified class, it automatically calls a special method called construc to build it. The name of the constructor is same as that of the class. If we do not provide constructors, Java will provide a default constructor automatically at run-time, + A constructor uses its parameters to initialize the new object's state, - Constructor does not return any value, not even void. A class can have any number of constructors all having the same name, each having different parameter lis This is known as constructor overloading. ._ Java keeps track of type signature while calling any method and constructor. M&M. Choice Quertions 1, A constructor .... (@ must have the same name as the class it is declared within, (b) is used to create objects. (© may be declared private @ aandb © a,bandec . 2. Which of the modifiers cannot be used for constructors ? (@) public ©) private © static @ protected 3, The term overloaded refers to. (@ anerror where more than one method matches a method tall (®) two or more methods in the same class that have the same name (© method calls where there are too many actual parameters (d) two or more methods in different classes that have the same name 4, Java will automatically define a constructor ... = (a) if the programmer does not define a default constructor for a class () if the programmer does not define any constructor for a class 3 34 $$$ $§_ IS 100% Suc CESS IN compirrer APPLICATIONS” (o if the program refers to a co, (@ for every class defined in p 5, The name of a constructor... (q) can be any legal identifie, A will always be the word new () must include the name of the package is i li 6, What is the prototype of default consinictor in the a will always be the same as the name of the class public class Test { } leclaration : public Test(void) / 5 None of these ©) Test (0) Test(void) (@ public Test() 7, Inthe statement, public class MyCar nstructor with no Parameters rogram, {}, what is the correct way of declaring a constructor ? MyCi " ; ® ae (®) MyCar(void) {} (€) public MyCar() {} (a) public MyCar(void) { | §, What is the return value of constructor in Java? @1 (©) null (0) void @) instance 9, The default constructor is used for’... aa @ calling default methods (©) De-ferencing default objects (©) Initializing default values to objects @) All of these 10, A constructor inside a class can be placed .... oo (a) at the beginning of class (b) at the end of class (©) anywhere in the class (@ before class name 1, A constructor can call another overloaded constructor using the ........... keyword in Java. (@ super © this (© local @ call 12, Method overloading is an OOP feature, that is... . (@ inheritance (© encapsulation (© polymorphism (@ None of these Answers L@ 2. 3.0 4. (b) 5.@ 6. @ 7.@© 8. @ 9.(¢) 10. () 11. ®) 12. © a LIBRARY CLASSES —— ‘The java. lang package is automatically imported into every Java Program. ‘The java, lang package provides classes, interfaces, classes for errors et The class Number is an abstract class. ‘The Number class constructor is written as Number( ). ‘The Byte class is a wrapper for byte integer type. ‘The Short class is a wrapper for short integer type. . The Integer class is a wrapper for integer type. . The function byte byteValue( ) is defined by all wrapper classes. . A package is a set of related classes. 10. A package can be used for encapsulation. . In Java, a library of classes is called ........ @ a folder (©) a package (© adirectory @ an application per awaenn 2. Integer isa... nO _ @ adapter class (©) inner class (©) nota class (@ wrapper class 3. Which of the following may be part of a class definition ? (@ instance variables (6) instance methods (c) constructors @ All of these (e) None of these 4, An object is an instance of a (@ program (©) class (© method 5. The keyword ... is required to declare a class, . cee (@) public (b) private (© class @ All of these @ superclass, Which is the most restrictivé a . You want subclasses in any package to have access to members of access that accomplishes this objective? (@) public (©) private (© protected 7. Which of these is a wrapper for data type int ? @ transient @ Integer : (6) Long © Byte 8. Which ofthese is aprocess of converting a simple datatype ito a class ? @ Both (a) and (6) above (@ type casting (©) type conversion () type wrapping 9, Which of these is a wrapper for simple data type char? *PPi"8 @ None of those (@) Float (© Character © String ea @ Integer lose SR% SUCCESS IN COMPUTER APPLICATIONS! Ju. HOSE snes Wranes fo ws sew suniuwing program 7 class Output{ public static void main (String args[]){ Integer i = new Integer(150); double x = idoubleValue(); System.out.print(x); } ( ; 150 (a) (b)1 .0 , Which of the following classes is not included in ie ? on (a) Class (b) Integer (© Byte @ Array . Each ee data type belongs to a specific: (@ Bloc (b) Obj . The valueOf() function oe (0 Wspper Css a (a) Primitive type to String (6) String to primitive type (c) Integer to Float @ Character to String . What will be the output of following program ? public class Test { public static void main(String args[ ]) { char ch boolean b = Character.isLetter(ch); System.out. printIn(b); } } @1 @o ©-1 @ false . What will be the output of following program ? public class Test { public static void main(String args }) { char ch = 'm’; char chr = Character.toUpperCase(ch); int a = (int) chr; System.out.printIn(chr + "\t" +a); } } @ M77 @7 M ON 16 @16 N . What will be the output of the following program ? public class Test { public static void main(String argsf ]) { char chr = 'C'; inti = 4; System.out.printin(chr + i); System.out.printin((int) chr + } } (@ 70 @71 (@ct+4 @4+c What will be the output of the following program ? Public class Test { ; public static void main(String arest J) { 1 muBIITER APPLICATIONS - 10 intn = 111; char ch = Character.toUpperCase ((char)n); System.out.printIn(ch + " My God!"); ; } (@) Runtime error (6) Mt God! 111 (¢) 111 My God! 18. What will be the output of the following program ? public class Test { public static void main(String args[ ]) { char ch = ‘a’: char chr = Character.toLowerCase(ch); int n = (int) chr + 20; System,out.printin((char) n+"\t" + chr); } } @u a (a 20 (at 20 19. What will be the output of the following program ? public class Test { public static void main(String args{ ]) { String str = "Best questions"; System. out. printin(str.replace('s', ' ')); } } , (@) Be t que tion (b) Bet question (©) Bess quession 20. What will be the output of the following program ? public class Test { public static void main(String args D { String str = "- Best questions"; String strl = "Best Answers"; System.out. printIn(str1.concat(str)); } (a) Best Answers Best questions- (© - Best Answers Best questions Anwwes 1. ® a 40 50 6 So a Ne | 9. ie, ales 17.@ 18. @ 19. @ 20. @ (@ O My God! @ 87 @ Best questions (®) - Best Answers-Best questions (@) Best Answers-Best questions 7..@ 8. 0) 15. @ 16. (b) ENCAPSULATION 1. Encapsulation means wrapping up of data and methods into single unit. 5 Dating is a way of preventing the user of an object from being directly accesséd by the data members of 3. Visibility means the way in which the properties of the base class are derived. 4, Visibility is of four types- public, private, protected and default. 5, Encapsulation is wrapping together the data and the methods that operate on it, into a single unit. 6. Information hiding is an outcome of encapsulation. 7. Encapsulation complements abstraction. 8. Encapsulation helps in concentrating on the important aspects and ignoring the rest. 9, Interface is the connection between the inner implementation part and the outer part without having to know the details of implementation. 10. Information hiding is an important feature of OOP. 11, Method signature acts as an interface for methods. 12, Abstract methods are class's interface. 13. The declaration of interface is same as that of class in Java. 14, In interface, the methods are just declared and not implemented. 15. The methods declared as interface have no body part. 16. To use an interface, a class must specify that implements the interface. 17. The class must define every method in the interface. 18. An access modifiers determines the accessibility of features of a class. 19. The four access modifiers of Java are : public, private, protected and default. H Choice Questions 1. Which feature can be implemented using encapsulation? @ Inheritance (b) Abstraction (©) Polymorphis: (@ Overloading 2, Normally all instance variables are given the qualifier... ae @ public (®) protected (© private @ static 3. A private instance variable... (@) can never be modified by a method method outside (0) can be modified by 4 yutside the class the class if it is returned by a method wins = 40 pe witha mutator metHO8) 2 ey, seinig a class t (©) can be modified by a method outside the class if its class (1 . by a method spy adot and ten te nam( (@ can be modified by using an object name followed PY |. Which is the advantage of encapsulation ? @ Only public methods are needed. : perce! (®) Making the class final causes no consequential changes to 0! 7 +s contract and (©) It changes the implementation without changing a class's co of the instance variay, - causes no consequential Change to other code. ; uses no consequential (@ Itchanges a class's contract without changing the implementation oe oe to other code. 5. Variables that are shared by every instances of a class are. ‘ies (@) class variables (@ public variables (6) private variables _(c) instance varial ‘bute into a class ? 6. Which concept of Java is achieved by combining methods and attribut ye (@) Encapsulation (6) Inheritance (©) Polymorphism 7. How can Encapsulation be achieved ? (@ Using Access Specifiers (6) Using only private members (© Using inheritance (@) Using Abstraction 8, The wrapping up of data and functions into a single unit is called : (@) Encapsulation (6) Abstraction (© Data Hiding (@ Polymorphism (©) Message passing 9 . Which among the following violates the principle of encapsulation almost always? (@ Local variables (b) Global variables (c) Public variables (d) Array variables 10. Which of the following concepts can be used for encapsulation in Java programs? (@) Wrapping data fields with methods i (© Hiding data and internal methods using access modifies in a class (© Using Interfaces @ Allof these + Which ofthe following members of the superclass is never accesible tothe subclass ? (@) public member (®) protected member () private member (4) All of these - How can the concept of encapsulation be achieved ina Tava program? (q) By using the Access specifiers (©) By using only private members i 13, A class member declared protected becomes a eae 12 wn the concept of Inheritance () By using the Concept of Abstraction : of subclass of whi (@) public member (6) private member (¢) protected Which type 2 14, Which keyword is used to inherit a class in Java ? ber @ static member (a) inherit () implement © : exte 15. Encapsulation helps in writing .... «classes in Java, 7a @ extena (@) Immutable (6) Abstract « ) (©) W . Which among the following should be encapsulated? PT (@) ‘The data which is prone to change in near future (®) The data prone to change after a long time (©) The data which is intended to be changed rn i @ The data 1 i isa ich belongs to some other class 0% SUCCESS IN CoMPUTER APPLICATIONS!” @ Immutable Which among the ing vie its ig the following violates the principle of encapsulation almost always ? (@ Local variables (6) Public vari 2 : variables ‘ A iables 18. Hiding the implementation complexity can (© Global variables 0 reyear (@ make the programming cas; ee ; y 6) mak ; = ° pumas ae 19. Encapsulation and abstraction differ in (a) binding and hiding respectively (©) can be used any way Which feature can be implemented using encapsula (@) Inberitance (b) hiding and binding respectively @ hiding and hiding respectively tion ? ¢ (©) Abstraction (© Overloading @ Overriding In Dog and Animal class, correct way of inheritance is. (@) class Dog extends Animal (©) both (a) and (b) are correct 20. 21. (6) class Animal extends Dog (@ both (a) and (6) are incorrect 22, Which member of the superclass cannot be accessed by the subclass? @ Public member (®) Protected member (c) Private member (d@) None of these 23. Which of the following keywords is used to refer to member of base class from a subclass? (@) upper (b) super (c) this (@ None of these 24. Which of the following is used for implementing inheritance through an interface? (@ inherited () implements (©) extends @ inherit Answers 1. 2@ 3.0 4© 5@ 6 @ 7.@ 8. (@) 9. (b) 10. @ 11. © 2 @ 13. 14. (©), 15. @) 16. (a) 1. 18. (@) 19. @ 20. @) 21. @ 2. 23. 24. (b) im sn08 YATIONS -10 82 |. The array whose elements are placed in a single subscript is called 01 . A subscript is represented by [ ]. |. Data grouped together into a single unit for a specific purpose is known as data structure. _ Array is a data structure where similar types of data are put together, stored in cor 12. 13. 14. 15. 16. 17. 18. 19. |. Searching and sorting are two basic array-processing techniques that are frequently used. 21. 22. ARRAYS ‘An array is a collection of data storage elements. An array is a fixed-size collection of finite number of elements. ‘A subscript is the number of elements within an array- | be ne dimensional array- Array having two subscripts is called two dimensional array. A string is a sequence of characters. Array elements can be sorted. Sorting may be in ascending or descendin Elements in an array can be searched by linear and binary search. g order. yntinuows locations and is| referred to by a single name. To refer to a particular location, we specify the name of the array and its position number. Position number is called an element or a subscript or an index of the array. ‘Subscript of an array must be an integer. In Java the index of first elements of an array is its zero and the last element is one less than the total elements in an array. Subscripts are enclosed within square brackets next to the name of the array. To retrieve an individual array element, array name along with its subscript should be specified. An array of smaller size can be initialised using an initializer list. Newly created array of integers is automatically filled with default values : 0 for numbers, false for boolean, and null for objects. a 7 Searching refers to finding an item in an array, depending on some specific criterion, Linear searching is the simplest searching method and i sequentially in an array. is done when the required element is searched| Binary searching isa faster way as it eliminates one half part every time while the search is carried earch is carried on. 1. Which of the following is correct usage ? (@) int array [-25] (©) float arr [25] 2, The string Hello Boys contains... characters : man! on ie ou 3, A string in Java program is written within (@ single quotes . . 4, A-string oe (© double quotes (@) begins with a null character (©) both of the above 5. Element arr [10] is which element of the array ? @ 10 ou 9 6. An array element is accessed ... (@ using dot operator @ None of these (© vsing an element name (@ None of these 7. The statement .. weight = {26, 28, 32, 31}; (@ None of these (@ None of these @o (®) ends with a null character (@ None of these (©) using an index number , (@) assigns 28 to weight [0] (©) assigns 28 to weight [1] (©) assigns 32 to weight [3] @ None of these 8. What will this code print ? int arr{] = new int [5]; System.out.printin(arr); @o © value stored in arr{0] (¢) 0000 9. Which of the following is advantage of Java array ? (@) Code Optimization (6) Random access _(c) Unlimited size 10. In Java, array elements are stored in ...........memory locations. (@ Random @ Sequential (© Sequential Random 11. What will be the output of the following Java code ? int arr{ ] = new int [5]; System. out. print(art); @o @l (@ 00000 12, Which of the following best describes an array ? @ A data structure that shows @ hierarchical behavior (© Container of objects of similar types (© Arrays are immutable once initialised @ Array is not a data structure ; 13. When does the ArraylndexOutofBounds Exception occur ? @ At Compile-time (b At Run-time (© It is not an error ESE 100% sucCESS IN COMPUTER APPLICATIONS - 10. @ garbage value @ Botha and b above @ Stacked @ Garbage value @ Itis not an exception at all 83 14, What are the advantages of using arrays ? (a) Objects of mixed data types can be stored (c) Index of first element of an array is 1 15. What are the disadvantages of arrays? (@) Data structure like queue or stack cannot be implemented (®) Index value of an array can be negative ay cannot be sorted inan arr (&) Elements in 7 tr jements of same datatype (@ Itis easy to store ¢ (©) Elements are sequentially accessed the allocated si (@) There is a wastage of memory space if elements inserted in an array are lesser ia ze ot ‘the array 16. Assuming int takes 4 bytes of memory, what is the size of int arr[15]; ? o bytes (@) 15 bytes (&) 19 bytes () 11 bytes 17. How many of the following are legal declarations ? char ] dog = new char{ J; char{ ] tiger = new char[1}; char{ ] horse = new J char; char[ ] cat = newf1] char; @ One © Two @.Four 18. In Java arrays are ...ssessseses + (@) objects © object references @ None of these 19. We can determine the length of an array using . (@) sizeof(array) (®) array.len (co) array.sizeof( ) @ array.length 20. At the time of array initialization which is necessary to specify? (@) Row (6) Column (©) Row and Column (@ None of these 21. Java array can allocate .... : @ Dynamic Memory (6) Static Memory _(c) Both (a) and (6) 22. Index in array start at .. : @-4t @o @1 @ infinite 23. Which is not a true statement? (@ Amarray can have duplicate values () An array understands the concept of ordered elements (©) Anarray uses a zero index to reference the first element @ Anarray expands automatically when it is full (@) None of these Anawers 1. @ 2.@ 3. © 4. ©) 5. (b) 6. () 7. (b) 8 @ 9. @ 10.) 1. @ 12. ® 13. ® 14. @ 15. @ 16. @) 17. @ 18. @) | 19. @ 20. @ 21. ® 2) 23.@ ane 2a nen einie fd eg ICSE 100% SUCHE Se mi ane STRING HANDLING aaa 1, String class is used when strings cannot change, 2, StringBuffer class is used when manipulation is required on a string. 3. '+" operator is used to concatenate strings, 4, length method is used to calculate the length of a string. 5, To extract characters from strings charAt() and getChars() methods are used. 6, substring) method returns a substring of the given string. 7. concat() method adds the specified string at the end of a given string. 8. trim method removes the blank spaces from both the ends of a string. M Choice Questions 1, Which of the following methods is used to concatenate strings? . @ getChars( ) () getBytes() (©) tocharArray() @ None of these A program segment is as follows ~ char a; a = "tdmalhotra’ charAt(); what will be the result of the segment ? x @m ®1 @a @ None of these 3. Which of the following method or words/characters is used to concatenate two strings ? @ add ®) join (© concat() @ None of these 4, Which of the following can be used to concatenate strings ? (@ + operator (b) && operator (©) toCharArray @ None of these 5. String declaration is terminated by .... (@) comma (®) semicolon Or @ quotes 6. String is delimited by @ single quotes (®) double quotes (©) without quotes (@ None of these 7. Which of the following methods of String class can be used to test to strings for equality ? @ isequal() (b) isequals() (© equal() @ equals() 8, Which of the following statement is incorrect ? (@ String is a class (®) Strings in java are mutable (©) Every string is an object of class String (d) Java defines a class of String, called StringBuffer, which can alter the string Ween PRT lee sre ABPI ICATIONS - 10 SOWaD oF the A . Li 4 te on ayy mettets ot class String I AE eT ‘ ie eo emewi) (8) Starts() tis the valve renimed by flinetion compare TOO) @ reo (0) value les (©) Value greater than zero with plus sign (a) None of these 11, Which of the data type values is returned by equals() method of String class 7 @ char @ ine () boolean Sadie 12, Which of the following methods of String class is used (0 obtain character at specified index ? @ char) (®) Charat() (o) int charAt() (chard) 13. String in Java is a 5 (@) class (b) object 14, What will be the ourput of the following program ? public class Test{ public static void main(String args[ ]) { ‘String sl = "Java"; String s2 = "Java"; ‘System.out.printin(s1-equals(s2)); ‘System.out.printin(s1 == s2); } } (a) tue me © te false 15. What will be the output of the following program ? public class Test { public static void main(String args{ }) { String s1 = "Java"; String s2 = "Python"; System. out.printin(s1.charAu(0) > s2.charAt(0)); } 3 (a) true @®) false @-1 (@o 16. What will be the output of the following program ? public class Test { public static void main(String args{ } { (@ ews) () mtarenwithe © Inthe Invoking 8M than 76 yy Us Hews tu he atc cay fo, with ruins sign (@) character array (0) variable (© false true @ false false String sl = "Java"; String s2 = "Python"; ‘system. out.printin(s1 .compareTo(s2)); } i 5 6 @-6 @ 5 lose 100% success iv conPuTER APES i. What willbe th ouput ofthe flowing Program ? oblic class Test { publ static void man ting arg { String s1 = "10"; System. ut.print(s1.substing(1)); System.out pins. totrng); } } @ 000 © 100 18, What willbe he ouput of te following program ? public class Test { publi sate void maining ag int asclicode[ ] = (65, 97, 66, 98}; String = new Sting(asciicode, 1,3); System. out printings); (9 010 @ 110 } } (@) aBb ( Boa (© AbB 15, Which of the following methods of clas Sting is used to remove leading and trailing whitespaces ? (@) sansWith() (©) tim) (9 Trim) (4) TrimWith( ) 20. Which of the following methods of class StringBuffer is used to reverse sequence of characters? (®) reverseAll()) () reverseall() (©) Reverse( ) @ reverse( ) Arwen, 1@ 20 30 40 56 *@ 0H® LO R@ B@ 1) B® B96 n@ (@ Abb 60 1@ 8b) w@ 56. 16. @

You might also like