Logix - Book - 10 - Question - Bank - With AR Questions
Logix - Book - 10 - Question - Bank - With AR Questions
ICSE
Question Bank
Introduction to Java 6
Operators in Java 11
User-defined Methods 14
Input in Java 16
Constructors 27
Library Classes 29
Arrays 33
String Handling 35
s
Object Oriented Programming (OOP) represents the program as a set of objects.
An object is an identifiable entity that has a set of attributes, behaviour, and state.
Attributes are individual characteristics that differentiate one object from the other.
The action or operation an object can perform is called its behaviour.
The state of an object is defined by the set of values held by its attributes.
p
Objects that share the same attributes and behaviour are grouped together into a Class.
An object belonging to a particular class is known as an instance of that class.
Classes can be derived from other classes. A class that is derived from another class is called a subclass. The class from
i
which it is derived is called the superclass.
Four OOP principles are Abstraction, Encapsulation, Inheritance, and Polymorphism.
Abstraction refers to the act of representing essential features without including background details.
Encapsulation is a mechanism that binds the data and code together into a single unit.
Inheritance is a powerful mechanism by which one class acquires the properties of another class.
Polymorphism is the ability of a method or object to take on multiple forms.
K
There can be multiple abstractions of an entity depending on the perspective of the viewer.
The terms object and instance are often interchangeable.
A class is a logical construct whereas an object has a physical reality.
The class is a specification of a set of objects; it is not the actual object.
In the OOP terms, you define attributes through data items in the class. These data items are referred to as member
variables or instance variables. The behaviour is defined through methods. These methods are referred to as member
methods.
You can make the entire data and the code, contained in an object, a user-defined data type using the concept of a
class.
Communication with an object is done by sending a message to it. The message is a request for an object to perform
an action.
s
6. ...................................... refers to the act of representing essential features without including the background details.
a. Abstraction b. Inheritance
c. Encapsulation d. Polymorphism
7. Procedure Oriented Programming mainly uses ...................................... .
a. Top-down approach b. Top-down and bottom-up approach
p
c. Bottom-up approach d. None of these
8. ...................................... is the feature using which one class acquires the properties of another class.
i
a. Abstraction b. Inheritance
c. Encapsulation d. Polymorphism
9. The ability of a method or object to take on multiple forms is called ...................................... .
a. Abstraction b. Inheritance
c. Encapsulation d. Polymorphism
10. An object has ...................................... .
K
a. Attributes b. State
c. Behaviour d. All of these
11. A class is ...................................... .
a. An object factory b. A blueprint to create objects
c. A specification for objects d. All of these
12. ...................................... represents an entity in the real-world with its identity and behaviour.
a. A class b. An object
c. A procedure d. A method
13. ...................................... is a template to create similar objects that share common characteristics and behaviour.
a. A method b. A procedure
c. An attribute d. A class
14. The values of an object's ...................................... represent the state of the object.
a. methods b. procedures
c. attributes d. classes
15. The terms object and ...................................... are often interchangeable.
a. instance b. behaviour
c. attribute d. state
16. Which best characterizes Procedural Programming?
a. Encapsulation & Objects b. Functions & Procedures
c. Classes & Objects d. Event-Driven & GUI
s
7. Inheritance allows a class to acquire the properties of another class.
8. A class is a blueprint for the attributes and behaviours of a group of objects.
9. Objects from the same class do not share the same definition of attributes and behaviours.
10. A class is a specification about the object.
11. Only one instance can be created from a single class.
p
12. A class is a user-defined data type.
13. The terms object and instance are often interchangeable.
i
14. Collectively, the values of an object's attributes represent the state of the object.
15. Objects interact with each other through messages.
ANSWERS
A. Multiple Choice Questions.
1. c 2. c 3. b 4. d 5. c 6. a 7. a 8. b 9. d 10. d
11. d 12. b 13. d 14. c 15. a 16. b
K
B. State whether the given statements are True or False.
1. False 2. True 3. False 4. True 5. True 6. True 7. True 8. True 9. False 10. True
11. False 12. True 13. True 14. True 15. True
s
Java is a third-generation Object Oriented Programming language.
Java applications are platform independent, which means that Java applications can be run on any platform.
Java language was initially called Oak but was renamed Java.
A stand-alone Java application refers to a Java program that can run independently on a computer.
Java Applets are Java applications that run within a web browser.
p
An assembler is a program that translates code written in assembly language into machine code.
An interpreter is a program that reads the source code instructions and translates them into machine code line-by-line
during program execution.
i
A compiler is a program that translates code written in a high-level language into machine code.
A Java Virtual Machine (JVM) is a virtual machine that enables a computer to run Java programs.
The machine language for the Java Virtual Machine is called Java Bytecode.
The JVM also includes a Just-In-Time (JIT) compiler that compiles selected portions of Bytecode into executable code.
Java uses a combination of compilation and interpretation.
Java is secure because the Applets are confined to the JVM memory only.
K
Multiple Choice Questions.
1. Which language does the CPU understand?
a. Machine language b. Assembly language
c. High-level language d. English language
2. Stand-alone Java applications ...................................... for execution.
a. Need Java-compatible web browser b. Need an assembler
c. Do not need Java-compatible web browser d. Need a linker
3. What is the full form of JVM?
a. Java Visual Monitor b. Java Video Monitor
c. Java Virtual Monitor d. Java Virtual Machine
4. The full form of JRE is ...................................... .
a. Java Runtime Editor b. Java Runtime Environment
c. Java Runtime Expression d. Java Runtime Enabler
5. Java uses ...................................... for execution.
a. Compilation and interpretation b. Interpretation
c. Compilation d. None of these
6. A program that translates code written in a high-level language into machine code is called ...................................... .
a. Assembler b. Linker
c. Compiler d. None of these
7. A program that translates an assembly language program into machine code is called ...................................... .
a. Assembler b. Linker
c. Compiler d. None of these
s
a. Stand-alone applications b. Both stand-alone and internet applications
c. Internet applications d. None of these
10. Java applications can run on ...................................... .
a. Windows platform b. Macintosh platform
c. UNIX platform d. All of these
p
11. Java applications ...................................... .
a. are platform dependent b. do not need a platform to run
i
c. are platform independent d. cannot run on Windows
12. A Java program can run as a stand-alone application only if it has ...................................... .
a. a void method b. an overloaded method
c. a main method d. no methods
13. What is the extension of a Java source code file?
K
a. Java b. .txt
c. .class d. .BlueJ
14. What is the extension of a Java class file?
a. .obj b. Java
c. .class d. .BlueJ
15. Choose the correct statement.
a. Applets can be executed in a web browser only.
b. Applets can be executed in an applet viewer only.
c. Applets can be executed in both web browser and applet viewer.
d. Applet cannot be executed.
ANSWERS
Multiple Choice Questions.
1. a 2. c 3. d 4. b 5. a 6. c 7. a 8. d 9. b 10. d
11. c 12. c 13. a 14. c 15. c
s
A character set is a defined list of characters that can be used by a computer.
The ASCII character set is a 7-bit character set that defines 128 different characters (27 = 128).
The Extended ASCII code is an 8-bit character set that defines 256 different characters (28 = 256).
The Unicode character set uses 8 to 32 bits per character, so it can represent characters from written languages
throughout the world.
p
An escape sequence is a set of characters that has a special meaning to the Java compiler. In the escape sequence, a
character is preceded by a backslash (\).
Java offers five tokens - keywords, identifiers, literals, punctuators, and operators.
i
Keywords have a special meaning to the Java compiler.
Identifiers are used in a Java program to name its different components, such as variables, methods, classes, and
objects.
Literal is a sequence of characters that represent values in a program and are stored in variables.
Punctuators are symbols used for grouping and separating the code.
Operators are symbols used to perform arithmetic or logical operations in a given expression.
K
Java offers two categories of data types - primitive and non-primitive data types.
There are eight primitive types in Java which are byte, short, int, long, char, float, double, and boolean.
A variable is an identifier that denotes a storage location in computer memory to store a data value.
Memory locations whose values cannot be changed within a program are called constants or symbolic constants.
In Java, the modifier final can be applied to a variable declaration to ensure that the value stored in the variable cannot
be changed after the variable has been initialised.
s
a. character b. break
c. object d. attribute
8. Which of the following is not a legal identifier?
a. _room b. $Pay Amount
c. 10thClass d. nullValue
p
9. Which of the following is a default value of float data type?
a. 0 b. 0float
i
c. Of d. 0.0f
10. Which of the following is a default value of boolean data type?
a. true b. false
c. null d. void
11. Which of the following is an invalid integer?
K
a. 2222 b. 22222
c. 222 22 d. 222
12. Which of the following is not a character literal?
a. '\n' b. "n"
c. 'n' d. All of these
13. Which of the following punctuator is the statement terminator in Java?
a. ; b. ,
c. . d. All of these
14. Which of the following is not a primitive data type in Java?
a. boolean b. short
c. float d. class
15. What is the size of a long data type in Java?
a. 32 bits b. 64 bits
c. 48 bits d. Long data type is not supported in Java.
16. What is the size of a boolean data type in Java?
a. 1 bit b. 16 bits
c. 8 bits d. Boolean data type does not take any space in memory.
17. Single line comments can be added using ...................................... .
a. II b. /*......*/
c. // d. None of these
18. Which of the following changes a variable declaration into a constant?
a. const b. constant
c. static d. final
s
a. array b. interface
c. class d. boolean
p
2. The ASCll code for character 'Z' is 90.
3. The smallest unit in a Java program is known as token.
i
4. The Unicode character set uses 8 to 32 bits per character.
5. In an escape sequence, a character is preceded by a backward slash (\).
6. In Java, an identifier can begin with a $ sign.
7. The boolean data type is used for storing logical values.
8. Identifiers in Java may be of any length.
9. The char data type reserves 8 bits in memory.
K
10. Default value of reference data type is null.
11. To designate a literal constant of the type float, you must append the letter L to it.
12. Default value of char data type is '\u0000'.
13. If a literal constant contains a decimal point, then it is of the type double by default.
14. A variable can be used in a Java program even if it has not been declared.
ANSWERS
A. Multiple Choice Questions.
1. c 2. a 3. c 4. b 5. a 6. d 7. b 8. c 9. d 10. b
11. c 12. b 13. a 14. d 15. b 16. a 17. c 18. d 19. a 20. d
B. State whether the given statements are True or False.
1. False 2. True 3. True 4. True 5. True 6. True 7. True 8. True 9. False 10. True
11. False 12. True 13. True 14. False
s
An operator that has just one operand is known as a unary operator.
An operator that has two operands is known as a binary operator.
An operator that has three operands is known as a ternary operator.
Arithmetic operators are used to perform basic mathematical calculations like addition (+), subtraction (–),
multiplication (*), division (/), and remainder (%).
p
The outcome of the relational operations is a boolean value which is either true or false.
Logical operators operate only on boolean operands.
In the expression a AND b, if one operand evaluates to false, the result is false.
i
In the expression a OR b, if one operand evaluates to true, the result is true.
Precedence is the priority order of an operator according to which it is evaluated.
Associativity tells the direction of execution of operators ("Left to Right" or "Right to Left") when operators in an
expression have the same precedence.
A type conversion is a process that converts a value of one data type to another data type.
Type conversions automatically performed by the Java compiler are known as implicit type conversions.
K
Explicit type conversions are performed by the programmer using the cast operator.
s
c. x=1, y=0 d. x=0, y=1
9. The statement (1 >0) II (1 <0) evaluates to ...................................... .
a. 0 b. 1
c. false d. true
10. The statement (1 == 1 )? 1 : 0 evaluates to ...................................... .
p
a. 0 b. 1
c. false d. true
i
11. The expression 17 % 4 gives the output ...................................... .
a. 4 b. 3
c. 2 d. 1
12. Consider the following code snippet:
float x = 8.25F;
K
int y;
y = (int) x;
What are the values of x and y?
a. X = 8.25, y = 8 b. x = 8.0, y = 8.0
c. X = 8, y = 8.25 d. x = 8, y = 8
13. The expression 13 / 3 gives the output ...................................... .
a. 4 b. 3
c. 0 d. 1
14. The statement System.out.println("six" + 3 + 3); gives the output ...................................... .
a. six33 b. six6
c. 33six d. 6six
15. The expression 4 + 8 % 2 gives the output ...................................... .
a. 6 b. 8
c. 4 d. None of these
16. Implicit type conversion is also known as ...................................... .
a. Automatic type conversion b. Type promotion
c. Widening conversion d. All of these
s
11. The expression p =- 9 is same as p = p-9.
12. The assignment operator (=) is a binary operator.
13. The output of System.out.println(1 = = 1); is true.
14. Explicit type conversion is also known as coercion.
p
ANSWERS
A. Multiple Choice Questions.
1. b 2. a 3. d 4. b 5. d 6. c 7. c 8. b 9. d 10. b
i
11. d 12. a 13. a 14. a 15. c 16. d
B. State whether the given statements are True or False.
1. True 2. True 3. False 4. True 5. True 6. True 7. False 8. False 9. True 10. False
11. False 12. True 13. True 14. False
K
Copyright @ Kips Learning Pvt. Ltd 2024
Kips | 13
User-defined Methods
Key Points
s
A method is a named block of code within a class. It executes a defined set of instructions when called from another
part of the program.
Methods help in dividing complex programs into manageable code blocks.
The method name along with the list of parameters used in the method prototype is known as method signature.
A method returns value through a return statement.
p
All methods must return a value which must be of the same data type as defined in the method prototype. Only the
methods defined with void as their return type do not return a value.
The arguments that are passed to a method should be in the same number, of the same type, and in the same order
i
as the parameters defined in the method prototype.
The parameters that appear in the method invocation are called actual parameters.
The parameters that appear in the method definition are called formal or dummy parameters.
When you pass parameters to a method by value, the values of actual parameters are copied to the formal parameters.
In the pass by reference technique, the reference of the actual parameter is passed to the formal parameter.
Pure methods are those that do not change the original state of an object. They always return the same value when
K
the same arguments are given.
Impure methods are those that change the original state of an object. Every time they are called, they do not return
the same value even when the same arguments are given.
The methods which are accessed via an instance of the class are known as non-static methods.
The methods which can be accessed without an instance of the class are known as static methods.
The process of defining two or more methods with the same name but different signatures in a class is called method
overloading.
Ambiguous invocation is referred to the situation when there are two or more possible matches in the invocation of
an overloaded method.
s
a. Windows b. Multiple programs
c. Class d. Method or block it is declared in
8. The technique in which the change in the formal parameter gets reflected in the actual parameter is known as
...................................... .
p
c. call by argument d. call by method
9. In which technique are the values of actual parameters copied to the formal parameters?
i
a. call by reference b. call by value
c. call by argument d. call by method
10. A method with many definitions is known as ...................................... .
a. many method b. multiple method
c. void method d. overloaded method
K
B. State whether the given statements are True or False.
1. A method may contain any number of return statements.
2. The non-static methods need an instance to be called.
3. A method can return more than one value.
4. Methods defined as void must return a value.
5. The static methods need an instance to be called.
6. In Java, all primitive types are passed by value and all reference types are passed by reference.
7. You can place the return statement in a void method without any expression.
8. If a method returns a value, then it must be of the same data type as defined in the method prototype.
9. Parameters in the method definition are called dummy parameters.
10. Methods reside in a class in Java.
11. Method overloading is one of the ways by which Java implements polymorphism.
12. The scope of a local variable is limited to the method or the block it is declared in.
13. The keyword static makes a method a class method.
14. An impure method always returns the same value when the same arguments are given.
ANSWERS
A. Multiple Choice Questions.
1. d 2. c 3. a 4. b 5. b 6. b 7. d 8. a 9. b 10. d
B. State whether the given statements are True or False.
1. True 2. True 3. False 4. False 5. False 6. True 7. True 8. True 9. True 10. True
11. True 12. True 13. True 14. False
s
A package is a named collection of Java classes that are grouped together on the basis of their functionality.
A package that is contained in another package is known as a sub-package.
All the standard Java classes are stored in a package called Java.
An import statement can be used to bring certain classes or the entire package into the current program.
A stream in Java is a path along the data flows. It transfers data from a source to a destination.
p
The data from the keyboard is taken in by a special stream called System.in.
You can use an object of the Scanner class for reading keyboard input.
Errors are mistakes in a program that prevent it from its normal working. They are often referred to as bugs.
i
A syntax error occurs due to the fact that the syntax of the programming language is not followed correctly.
A runtime error occurs during the execution of a program.
A logical error occurs when the program compiles and runs without errors but produces an incorrect result.
K
netPay = grossPay + providentFund;
instead of:
netPay = grossPay - providentFund;
Assuming all the unseen code is correct, what kind of error is it?
a. Syntax error b. Runtime error
c. Logical error d. None of these
2. Which of the following might make the Java compiler report a syntax error in a particular line of a program?
a. The program is typed in the wrong font. b. The line contains a comma (,) instead of a dot (.).
c. It is caused by Java runtime. d. Program takes too long to compile.
3. Which of the following statement is true for logical errors?
a. The compiler does not detect these errors.
b. There is no indication of error when the program is executed.
c. The program may produce correct results for some input data and wrong results for other input data.
d. All of the above
4. Which keyword do you use to include a class in your program?
a. import b. export
c. include d. impart
5. Which of the following is not a valid method of the Scanner class?
a. next() b. nextlnt()
c. nextlong() d. nextNumber()
6. Default delimiter used in the Scanner class is ...................................... .
a. Comma b. Whitespace
c. Colon d. There is no default delimiter.
s
a. java.util .* b. java.awt.*
c. java.io.* d. java.lang.*
9. Errors occur in a program when ...................................... .
a. Syntax of the programming language is not followed.
b. The program does not run properly or does not execute at all.
p
c. The program produces an incorrect result.
d. All of the above
i
10. The Scanner class can be used to read input from ...................................... .
a. a keyboard b. a file
c. a string d. All of these
ANSWERS
Multiple Choice Questions.
K
1. c 2. b 3. d 4. a 5. d 6. b 7. a 8. a 9. d 10. d
s
A user-defined method is a method defined by the user.
The methods created by the developers of Java are called library methods or built-in methods, which are available in
the form of packages.
java.lang package includes the Math class.
The Math class contains lot of generic mathematical functions, including geometric and trigonometric functions.
p
Since the java.lang package is used in almost every Java program, it is imported, by default, by the Java compiler even
if you do not explicitly import it.
i
Multiple Choice Questions.
1. What will be the output of Math.cbrt(–125)?
a. 5.0 b. 0.0
c. –5.0 d. error - can't use Math.cbrt0 on a negative number
2. Which Java package includes the Math class?
K
a. java.io b. java.lang
c. java.util d. java.sys
3. Give the output of Math.sqrt(x); when x = 9.0
a. 3 b. 3.0
c. 3.00 d. All of these
4. Give the output of Math.ceil(–0.6).
a. –1.6 b. –1.5
c. –1.0 d. –0.0
5. Give the output of Math.ceil(–46.6).
a. –46.6 b. –46.5
c. –1.0 d. –46.0
6. Give the output of Math.abs(x); when x = –9.99
a. –9.99 b. 9.99
c. 0.99 d. None of these
7. Which of the following is a method to find the square root of a number?
a. Find Squareroot(x) b. Sqrt(x)
c. Math.Square(x) d. Math.sqrt(x)
8. What will be the output of Math.pow(3, 0)?
a. 0.0 b. 1.0
c. 3.0 d. –1.0
9. Math.random() returns a double value r such that ...................................... .
a. 0.0 ≤ r < 1.0 b. 0.0 ≤ r ≤ 1.0
c. 0.0 < r ≤ 1.0 d. 0.0 < r < 1.0
s
a. 0.0 b. 0
c. 1 d. 1.0
12. What will be the output of Math.abs(–0)?
a. 0.0 b. 0
c. –0 d. +O
p
13. Given the following statements:
int min = 1, max= 10;
i
int range= max – min + 1;
int num = (int) (range * Math.random() + min);
The value of num will be in integer such that ...................................... .
a. 1 <= num <= 10 b. 1 <= num < 10
c. 1 < num <= 10 d. 1 < num < 10
K
ANSWERS
Multiple Choice Questions.
1. c 2. b 3. b 4. d 5. d 6. b 7. d 8. b 9. a 10. b
11. c 12. b 13. a
s
A conditional or decision statement allows you to check a condition and execute a certain part of the code depending
on whether the condition is true or false.
A block consists of a sequence of statements enclosed between a pair of curly brackets.
Java provides two types of conditional statements: if and switch.
The switch statement is used when there is a requirement to check multiple conditions in a program.
p
An if statement that contains another if statement in its if-part or else-part or both is called a nested if statement.
An if-else statement can be used as an alternative to the conditional operator.
The break statement is used inside the switch statement to terminate a statement block. It brings the program control
i
out of the switch statement.
The absence of break statement in a case causes the control falling through the following case statements.
The default case is the last statement of the switch statement. It is an optional statement. It executes only when the
value stored in switch expression does not match with any case label.
You can exit the currently running program via the exit() method of the System class - System.exit(n). The argument
n serves as a status code. A non-zero status code indicates abnormal termination, and a zero status code indicates a
K
normal termination.
s
System.out.println("Apple");
break;
case 3:
System.out.println("Orange");
break;
p
default:
System.out.println("Fruitless");
i
}
a. Orange b. Banana
c. Apple d. Fruitless
5. Predict the output of the following code snippet:
int a= 1;
K
int b = 2;
if (a== b)
System.out.println ("Both values are equal");
else
System.out.println ("Values are not equal");
a. Both values are equal b. Incorrect use of the = = operator
c. Values are not equal d. No output
6. Consider the following code snippet:
if ( c > d)
x = c;
else
x = d;
Choose the correct option if the code mentioned above is rewritten using the ternary operator:
a. x = (c >d)? c : d; b. x = (c >d)? d : c;
c. x = (c >d)? c : c; d. x = (c >d)? d : d;
7. if ((a > b) && (a > c)), then which of the following statements is true?
a. a is the largest number. b. b is the largest number.
c. c is the largest number. d. b is the smallest number.
8. Consider the following code snippet:
int val= 2;
switch (val)
{
case 1: "System.out.println("Case 1 ");
break;
s
}
Which of the following statements is correct?
a. case 1 will be executed. b. case 2 will be executed.
c. default will be executed. d. both case 1 and 2 will be executed.
9. A sequence of statements enclosed between a pair of curly brackets is called ...................................... .
p
a. a compound statement b. an empty statement
c. a null statement d. a void statement
i
10. Which clause is optional in the switch statement?
a. default b. case
c. switch d. None of these
11. Which of the following statements involves a fall-through?
a. if-else b. for loop
K
c. if-else-if ladder d. switch
12. Which of the following causes a fall-through in the switch statement?
a. Omission of fall b. Omission of continue
c. Omission of break d. Omission of loop
13. Which of the following is mandatory in the switch statement?
a. break b. continue
c. case d. default
14. Which of the following statement is a valid combination?
a. if inside switch b. switch inside if
c. else inside switch d. default inside if
ANSWERS
Multiple Choice Questions.
1. d 2. d 3. b 4. d 5. c 6. a 7. a 8. b 9. a 10. a
11. d 12. c 13. d 14. a
s
Java offers three types of basic building blocks (referred to as constructs) to write computer programs - sequencing,
selection, and iteration or looping.
Java offers three types of looping controls: for, while, and do-while.
In an entry-controlled loop, the test condition is evaluated before the start of the loop. The for and while loops are
entry-controlled loops.
In an exit-controlled loop, the test condition is evaluated at the end of the body of the loop. The do-while loop is an
p
exit-controlled loop.
A loop that never terminates is called an infinite loop.
i
A for loop can just contain a null statement, i.e., just a semicolon (;). Such a loop is called an empty loop.
A do-while loop is always executed once.
A break statement terminates the current loop or switch statement. The execution then continues from the statement
immediately following the current loop or switch statement.
The continue statement skips the rest of the current iteration of the loop and jumps back to the beginning of the loop
and continues with the next iteration.
K
A. Multiple Choice Questions.
1. Which of the following segment can be omitted in a for loop?
a. Initialisation b. Test condition
c. Update expression d. All of these
2. Which of the following loop executes at least once?
a. while b. for
c. do-while d. None of these
3. Which of the following is an exit-controlled loop?
a. while b. do-while
c. for d. None of these
4. Which of the following is an invalid loop?
a. repeat b. for
c. do-while d. while
5. Which of the following statement causes complete termination of the loop?
a. continue b. jump
c. break d. terminate
6. Which of the following is an empty loop?
a. for (i = 0; i < 5; i++); b. while (i < 5) i++;
c. do {i++;} while (i < 5); d. All of these
7. Which of the following is not a jump statement in Java?
a. break b. jump
c. return d. continue
s
}
a. 0 b. 1
c. 5 d. 4
9. What will be the output of the following code?
public static void main(String args[])
p
{
int sum = 0;
i
for (int i= 1; i <= 5; i ++)
{
sum= i;
}
System.out.println( sum);
K
}
a. 15 b. 21
c. 5 d. 0
10. How many times will the following loop execute?
public static void main(String args[])
{
int sum = 0;
for (int i= 10; i > 5; i++)
{
sum += i;
}
System.out.println(sum);
}
a. 5 b. 0
c. 15 d. Infinite loop
11. Which of the following for loops will cause the body of the loop to be executed 10 times?
a. for (int i= 0;i < =10; i++ ) b. for (int i=1;i<10;i++ )
c. for (int i= 10; i >1 ; i-- ) d. for (int i= 0;i<10;i++ )
12. How many times will the following loop execute?
public static void main(String args[])
{
int i= 1;
while (i < 10)
s
c. 0 d. 10
p
3. The while part of a do-while statement must be terminated by a semicolon.
4. All types of loops in Java (for, while, and do-while) can be infinite loops.
i
5. The continue statement terminates the current loop and then continues from the statement immediately following the
current loop.
6. The return statement is a jump statement.
7. The for loop may contain multiple initialisations and updates.
8. A loop that never terminates is called an empty loop.
9. The do-while loop executes at least once even if the condition is false.
K
10. The do-while loop is an exit-controlled loop.
11. An infinite loop can be constructed using a while loop only.
12. The statements that facilitate unconditional transfer of control are called jump statements.
ANSWERS
A. Multiple Choice Questions.
1. d 2. c 3. b 4. a 5. c 6. a 7. b 8. b 9. c 10. d
11. d 12. a
B. State whether the given statements are True or False.
1. False 2. False 3. True 4. True 5. False 6. True 7. True 8. False 9. True 10. True
11. False 12. True
s
When one loop is inside the body of another loop, it is called a nested loop.
The break statement in an inner loop causes termination of the inner loop only.
The continue statement in an inner loop causes skipping the rest of the current iteration of the inner loop only.
Labels are named blocks in a Java program.
Loops can also be labelled.
p
The break statement terminates the labelled statement; it does not transfer the flow of control to the label. Control
flow is transferred to the statement immediately following the labelled (terminated) statement.
In a labelled continue statement, the control is transferred to the named block.
i
Multiple Choice Questions.
1. What is a nested loop in Java?
a. A loop with a fixed number of iterations b. A loop inside another loop
c. A loop that runs only once d. A loop with a conditional statement
2. What is the primary purpose of using nested loops?
K
a. To increase the complexity of the code b. To reduce the execution time
c. To iterate over elements of an array or collection d. To create an infinite loop
3. Which keyword is used to break out of the innermost loop in a nested loop structure?
a. exit b. break
c. terminate d. escape
4. In a nested loop, if the outer loop has 'm' iterations and the inner loop has 'n' iterations, how many total iterations will be
performed?
a. m b. n
c. m * n d. m + n
ANSWERS
Multiple Choice Questions.
1. b 2. c 3. b 4. c
s
A constructor is a member method of a class that is used to initialise the instance variables and perform other
important tasks.
The constructor has exactly the same name as its defining class.
The constructor method does not have a return type — not even void.
A constructor can be invoked only via the new operator; you cannot invoke it as a normal method call.
p
A default constructor is a constructor that accepts no arguments and has no statements in its body.
A constructor with no parameters is called a non-parameterised constructor. Since the default constructor has no
parameters, it is also known as a non-parameterised constructor.
i
A constructor with parameters is called a parameterised constructor. The parameterised constructor allows the
programmer to initialise objects with different values when they are created.
Execution of at least one constructor is a must when an object of the class is created.
The process of creating more than one constructor with the same name in a class is called constructor overloading.
The signature of all versions of the constructor should be different for the constructor overloading purpose, i.e., they
should have different number and data types or arrangement of parameters.
K
Within a constructor or an instance method, this is a reference to the current object — the object whose constructor
or method is being invoked.
s
d. All constructors must have no arguments.
ANSWERS
Multiple Choice Questions.
1. c 2. d 3. a 4. a 5. d 6. a
i p
K
Kips | 28 Copyright @ Kips Learning Pvt. Ltd 2024
Library Classes
Key Points
s
Primitive data types are pre-defined by the language and form the basic building blocks of representing data.
A composite data type is a data type which can be constructed in a program using the programming language's
primitive data types.
The data type defined by the user to perform some specific task is known as a user-defined data type.
The class can also be considered as a new data type created by the user, that has its own functionality.
p
A wrapper class allows you to convert a primitive data type into an object type. Each of Java's eight primitive data
types has a wrapper class dedicated to it.
The wrapper classes Integer, Long, Float, and Double have corresponding methods to parse a string argument as a
i
numeric value.
The Character class wraps a value of the primitive type char into an object.
Autoboxing is the automatic conversion of the primitive types into their corresponding object wrapper classes.
Auto-unboxing is the reverse process of Autoboxing. That means, it is an automatic conversion of the object wrapper
classes into their corresponding primitive types.
K
Multiple Choice Questions.
1. Which of the following is a primitive data type?
a. int b. float
c. char d. All of the these
2. Which of the following is a composite data type?
a. int b. float
c. char d. String
3. The return type of the isLowerCase() method is ...................................... .
a. int b. boolean
c. char d. String
4. The return type of the toLowerCase() method is ...................................... .
a. int b. boolean
c. char d. String
5. The value returned by Integer.parseInt("–321") is ...................................... .
a. –321 b. 321
c. 321.0 d. "321"
6. Name the method that can convert a string into its integer equivalent.
a. Integer.parseInteger() b. Integer.getlnt()
c. Integer.parseInt() d. Integer.readInt()
7. In which package is the wrapper class Integer available?
a. java.io b. java.util
c. java.awt d. java.lang
s
c. An array count will be initialised with 12 elements, all having a default value of zero (0).
d. Value of count will be unknown as no value has been assigned yet.
ANSWERS
Multiple Choice Questions.
1. d 2. d 3. b 4. d 5. a 6. c 7. d 8. a
i p
K
Kips | 30 Copyright @ Kips Learning Pvt. Ltd 2024
Encapsulation and Inheritance
Key Points
s
Encapsulation refers to the process wherein the data and the operations are combined together into a single unit (in
OOP terms, a class), and the details of the implementation are hidden.
The property which controls the accessibility of member variables (data) and member methods in a class is known as
access specifier.
There are three types of access specifiers in Java: public, private and protected.
The class members (variables and methods) declared with the public access specifier can be accessed from outside the
p
class.
The class members (variables and methods) declared with the private access specifier can be accessed within the
i
same class only.
The class members (variables and methods) declared with the protected access specifier can be accessed within the
same package only.
The scope of a variable refers to that part of the program in which the variable is accessible.
The variables declared inside a method or "block" are called local variables. Their scope is limited to the method or the
block they are declared in.
The variables used as arguments in the method heading are called argument variables. Their scope is limited to the
K
method where they are being used.
The member variables in a class that are used to store the individual states (attributes and behaviour) of an object are
called instance variables.
A variable declared in a class with the static modifier is called a class variable. The static variable will be available as a
single copy to all instances of the class.
An instance is required to access an instance variable.
An instance is not required to access a class variable.
Inheritance is a mechanism of deriving a new class from an existing class.
The class that gets inherited (derived) is called the parent class.
The class that inherits is called the child class.
When a class is derived from only one base class, it is known as single inheritance.
When a sub class is inherited from multiple base classes, it is known as multiple inheritance.
When many sub classes are inherited from a single parent class, it is known as hierarchical inheritance.
When more than one type of inheritance forms are used together, it is known as hybrid inheritance.
When a sub class is inherited from a class that itself is being inherited from another class, it is known as multilevel
inheritance.
s
a. Class b. Package
c. Subclass c. All of these
5. A member variable declared with no access specifier has visibility in ...................................... .
a. Class and package b. Class, package and subclass
c. Class and subclass d. Class
p
6. An instance variable ...................................... .
a. needs an instance to access it b. does not need an instance to access it
i
c. can be accessed using the class name d. is declared with the static keyword
7. A static variable ...................................... .
a. is preceded by static keyword in the declaration b. is accessed via the class name
c. is also known as a class variable d. All of the above
8. ...................................... is the feature by means of which one class acquires the properties of another class.
K
a. Abstraction b. Inheritance
c. Encapsulation d. Polymorphism
9. The class that gets inherited is known as ...................................... .
a. Parent class b. Base class
c. Super class d. Subclass
10. When many sub classes are inherited from a single base class, it is known as ...................................... .
a. Hierarchical inheritance b. Multiple inheritance
c. Single inheritance d. Multilevel inheritance
ANSWERS
Multiple Choice Questions.
1. c 2. d 3. d 4. a 5. a 6. a 7. d 8. b 9. d 10. a
s
An array is a structure to store a number of values of the same data type in contiguous memory locations.
Data values in an array are called array elements.
We can use the length property to determine the size of an array.
A Java array is a reference data type.
Starting with the first element (0th element), the linear search sequentially checks each element of the list for the
p
target value until a match is found or all the elements have been searched.
A linear search can be used with both sorted and unsorted arrays.
In the binary search, the array is divided into two halves. Depending on which half of the element is present, that half
i
is further divided into two halves and the process is repeated until the search element is found or not found.
A binary search can be used with sorted arrays only.
The selection sort is a combination of searching and sorting. During each pass, the unsorted element with the smallest
(or largest) value is moved to its final position in the array.
Bubble sort is a sorting algorithm that works by repeatedly iterating through the array to be sorted, comparing each
pair of consecutive items and swapping them if they are in the wrong order.
K
Multiple Choice Questions.
1. The size of an array that signifies the number of elements it can store is given using ...................................... brackets.
a. {} b. []
c. () d. All of these
2. Given array int x[] = {11, 22, 33, 44}; the value of x[1] is ...................................... .
a. 11 b. 22
c. 33 d. Invalid value
3. Given array int x[] = {11, 22, 33, 44}; the value of x[1+2] is ...................................... .
a. 11 b. 22
c. 33 d. 44
4. If int arr[] = {3, 5, 7, 9}; what is the value of arr.length?
a. 3 b. 5
c. 4 d. Cannot be determined
5. Given array int z[] = {15, 16, 17}; It will occupy ...................................... bytes in memory.
a. 3 b. 12
c. 24 d. 64
6. A linear search ...................................... .
a. can be used with sorted arrays only
b. can be used with unsorted arrays only
c. can be used with both sorted and unsorted arrays
d. cannot be used with arrays
s
d. cannot be used with arrays
8. Which of the following statements is true?
a. Binary search is less efficient than the sequential search.
b. Binary search is less efficient than the linear search.
c. Binary search is more efficient than the sequential search.
p
d. Binary search is as efficient as the sequential search.
9. In ...................................... search, the algorithm uses the middle value of the array for the search operation.
i
a. Binary b. Linear
c. Bubble d. Selection
10. Which element is num[9] of the array num?
a. 8th b. 9th
c. 10th d. 11th
K
ANSWERS
Multiple Choice Questions.
1. b 2. b 3. d 4. c 5. b 6. c 7. a 8. c 9. a 10. c
s
String is a class in Java.
Each character in a string has an index which denotes its position within the string.
Strings in Java follow zero-based indexing because the string indexes start at zero.
The trim() method of the String class removes the leading and trailing spaces from a string.
The toLowerCase() method converts each character in a string to lowercase.
p
The toUpperCase() method converts each character in a string to uppercase.
The length() method returns the length of a string.
The charAt() method returns the character value at the specified index of the string.
i
The indexOf() method returns the index (position) of the first occurrence of the specified character.
The lastrndexOf() method returns the index (position) of the last occurrence of the specified character.
The concat() method joins (concatenates) two strings.
The equals() method compares two strings to check whether they are equal or not.
The equalsIgnoreCase() method compares two strings to check whether they are equal or not after ignoring the case
(uppercase or lowercase).
K
The compareTo() method compares two strings lexicographically, i.e., alphabetically lengthwise and character-wise.
The compareToIgnore() method compares two strings lexicographically, i.e., alphabetically lengthwise and
characterwise, ignoring case differences.
The replace() method returns a new string resulting from replacing all occurrences of a character in the string with
another character.
The substring() method returns a new string that is a substring of the given string.
The startsWith() method returns true if the given string starts with the specified prefix, returns false otherwise.
The endsWith() method returns true if the given string ends with the specified suffix, returns false otherwise.
The valueOf() method returns the string representation of the argument.
s
method. If the character is present in the string, the
method will return the index number; otherwise, it will
return –1.
lastindexOf() stringObject.lastindexOf(char) The lastindexOf() method returns the index (position)
of the last occurrence of the specified character in a
p
string. This means that if a character occurs more than
once in the string, the lastindexOf() method returns the
index value of its last occurrence. If the character does
i
not occur in the string, it returns –1.
concat() stringl.concat(string2) The concat() method joins or concatenates two strings.
equals() stringl.equals(string2) The equals() method compares two strings to check
whether they are equal or not. The result is a boolean
value true if they are equal, otherwise the result is false.
For this method, the corresponding uppercase and
lowercase characters are different. That means, 'G' and
K
'g' are not equal.
equalsignoreCase() stringl.equalsignoreCase(string2) The equalslgnoreCase() method compares two strings
to check whether they are equal or not after ignoring
their case (uppercase or lowercase). The result is a
boolean value true if they are equal, otherwise the
result is false. For this method, the corresponding
uppercase and lowercase characters are the same. That
means, 'G' and 'g' are equal.
compareTo() stringl.compareTo(string2) The compareTo() method compares two strings. It not
only checks the equality of the strings but also checks
whether a string is bigger or smaller than the other
string.
compareToignore() stringl.compareToignoreCase(string2) The compareTolgnore() method compares two strings
lexicographically, ignoring case differences in the strings.
replace() stringObject.replace (oldChar, newChar) The replace() method replaces all occurrences of a
character in a string with another character.
substring() stringObject.substring(startlndex) The substring() method returns a new string that is a
substring of the given string.
substring() stringObject.substring(int startlndex, int This is another variant of the substring() method that
endlndex) returns a new string which is a substring of the given
string. However, the substring begins at the specified
startlndex and extends to the character at index end
Index –1.
startsWith() stringObject.startsWith(prefixStr) The startsWith() method checks whether a string starts
with a particular string (prefix). The method returns
true if the given string starts with the specified prefix,
otherwise it returns false.
s
otherwise it returns false.
valueOf() String.valueOf(data) The valueOf() method returns the string representation
of the argument.
p
1. The trim() method of the String class removes ...................................... .
a. leading spaces only b. trailing spaces only
i
c. spaces in between words d. leading and trailing spaces
2. While using the toLowerCase() method on a string containing special characters, ...................................... .
a. the special characters remain unaffected.
b. the special characters are converted to spaces.
c. the special characters are converted to null character.
K
d. the special characters are removed from the string.
3. The index of a string ...................................... .
a. ranges from 0 to the length –1 of the string
b. ranges from 0 to the length of the string
c. ranges from 1 to the length of the string
d. ranges from 1 to the length –1 of the string
4. The indexOf0 method returns the position of the ...................................... .
a. first occurrence of the specified character
b. last occurrence of the specified character
c. null character
d. '\n' character
5. The return type of the equals() method is ...................................... .
a. int b. char
c. boolean d. void
6. Which one of the given statements is true for the following statement?
string1.compareTo(string2)
a. if string1 > string2 the result will be a negative integer i.e. < 0.
b. if string1 > string2 the result will be a positive integer i.e. > 0.
c. if string1 > string2 the result will be 0.
d. None of the above
7. Which one of the given statements is true for the following statement?
string1.compareTo(string2)
a. if string1 > string2 the result will be a positive integer i.e. > 0.
b. if string1 < string2 the result will be a negative integer i.e. < 0.
s
b. int representation of the argument
c. boolean representation of the argument
d. character representation of the argument
9. Output of the following statement is ...................................... .
System.out.print!n("SUNDAY".substri ng(3));
p
a. NDA b. DAY
c. SUN d. N
i
10. Output of the following statement is ...................................... .
System.out.println("WONDERFUL".substring(3,4));
a. DERF b. NDER
c. D d. N
ANSWERS
K
Multiple Choice Questions.
1. d 2. a 3. a 4. a 5. c 6. b 7. d 8. a 9. b 10. c
s
Question 1:
Assertion (A): Java is platform-independent due to its "Write Once, Run Anywhere" (WORA) capability.
Reason (R): Java code is compiled into bytecode, which can run on any platform with a compatible Java Virtual Machine (JVM).
(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).
p
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
i
Question 2:
Assertion (A): In procedure oriented programs, more emphasis is given on the functions.
Reason (R): Functions share the global data when it interacts with variables that are declared outside of its own scope.
(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.
K
(d) Assertion (A) is false and Reason (R) is true.
Question 3:
Assertion (A): A class represents a group of objects of the same kind.
Reason (R): Objects of the class are treated as variables of the type class.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 4:
Assertion (A): When one type of value is assigned to another type of variable, the data type is converted automatically.
Reason (R): A variable of lower data type is converted to a value of higher data type.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 5:
Assertion (A): An accumulator is a variable used to calculate the sum or product of a series.
Reason (R): An accumulator stores the intermediate result of calculations.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 7:
p
Assertion (A): The Scanner class is present in java.util package is used to read input from the keyboard.
Reason (R): The System.in parameter passed to the Scanner constructor allows it to read input from the standard input stream.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
i
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 8:
Assertion (A): The break statement in the switch construct is used to terminate the sequential execution of statements.
K
Reason (R): The break statement transfers the execution outside the switch block.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 9:
Assertion (A): The counter variable stores an initial value and gets updated when a condition is satisfied.
Reason (R): It checks the execution of the if-else statement.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 10:
Assertion (A): The continue statement changes the flow of execution to stop the sequential execution and resume the condition
check.
Reason (R): It takes the loop for the next iteration.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 11:
Assertion (A): A class encapsulates the data members and member functions. It is used to create an object.
Reason (R): A class is responsible for creating objects based on its blueprint.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
s
Assertion (A): Primitive data types are independent data types and has a fixed memory.
Reason (R): Non-primitive types may have dynamic memory allocation.
(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).
p
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
Question 13:
i
Assertion (A): The infinite loop never terminates.
Reason (R): In the infinite loop, there is a condition that never returns false.
(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.
K
(d) Assertion (A) is false and Reason (R) is true.
Question 14:
Assertion (A): The JVM is invoked to interpret or execute the compiled Java bytecode.
Reason (R): Java code can be written once and executed on various platforms without modification.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 15:
Assertion (A): In Java, the final keyword is used to declare constants.
Reason (R): Constants declared with final cannot be reassigned once their values are initialised.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 16:
Assertion (A): Two objects need to communicate with each other in order to interact.
Reason (R): The communication between objects is referred to as message passing.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 18:
p
Assertion (A): A variable declared within the body of a method cannot be accessed outside the method.
Reason (R): The variables declared within the body of a method are called local variables.
i
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 19:
K
Assertion (A): A static member variable can be accessed only in the static methods without associating with an object.
Reason (R): Non-static member variables can be accessed in static methods by associating them with objects separated by a
dot.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 20:
Assertion (A): A class is called a composite data type.
Reason (R): A class binds up one or more primitive types together as a single data type.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 21:
Assertion (A): The main function is the most important function in a java program.
Reason (R): The main function is called by the import keyword.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 23:
p
Assertion (A): Functions support the reusability of codes.
Reason (R): The code written once as a function can be called whenever required.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
i
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 24:
Assertion (A): Breaking down a program into simpler tasks and organising the code using functions is a good practice.
K
Reason (R): It increases the complexity of the programs.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 25:
Assertion (A): In a function's parameter list, you specify the data type followed by the variable name.
Reason (R): Parameters act as placeholders to receive values when a function is called. The values passed to the function during
the function call.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 26:
Assertion (A): In the call by reference, the changes in formal parameters will be reflected in the actual parameters.
Reason (R): The formal parameters will be the reference variables when the function is called by reference.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 28:
p
Assertion (A): In a pure function, there is no change in the state of the function.
Reason (R): A pure function always returns a value.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
i
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 29:
Assertion (A): There are no restrictions on the number of return statements that may be present in a function.
K
Reason (R): The execution of a function terminates once a return statement is encountered, regardless of the number of return
statements present.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 30:
Assertion (A): A constructor does not have a return type.
Reason (R): A constructor should be defined with a public access specifier or no access specifier.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 31:
Assertion (A): A constructor automatically gets invoked whenever object of the class is created.
Reason (R): The name of the constructor is same as that of the class name.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 32:
Assertion (A): A non-parametrized constructor does not accept any parameter.
Reason (R): It gets the values from the object when it is created.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
s
Assertion (A): A constructor can be created anywhere in the class.
Reason (R): The constructor gets called when the object of the class is created.
(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).
p
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
Question 34:
i
Assertion (A): We can have more than one constructor in a program. This is known as Constructor Overloading.
Reason (R): In Constructor Overloading all constructors are called together.
(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.
K
(d) Assertion (A) is false and Reason (R) is true.
Question 35:
Assertion (A): The private data members are not accessible outside the class by any means.
Reason (R): A constructor is used to assign the initial values to private data members of the class.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 36:
Assertion (A): The number of actual parameters cannot be different from the number of formal parameters.
Reason (R): If a class is called its constructor is automatically created.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 37:
Assertion (A): The classes contained in packages can be reused in other programs without physically copying them into the
program.
Reason (R): The predefined classes of java get included in an application program itself.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 39:
p
Assertion (A): Autoboxing is responsible for converting primitive data type values to corresponding wrapper classes.
Reason (R): The wrapper class is helpful in creating objects of the classes which will be similar to the primitive data types.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
i
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 40:
Assertion (A): Java treats uppercase and lowercase letters differently.
K
Reason (R): Java is a case sensitive programming language.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 41:
Assertion (A): Storing data from a wrapper object to a primitive variable is known as Unboxing.
Reason (R): Wrapper classes in Java provide methods like intValue(), doubleValue(), etc., to extract primitive values.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is 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.
(d) Assertion (A) is false and Reason (R) is true.
Question 42:
Assertion (A): In a Java program, data members and methods are bound in a single unit.
Reason (R): The wrapping up of data and functions in a single unit is called encapsulation.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 43:
Assertion (A): The class variables are associated with the class rather than its objects.
Reason (R): The values that class variables take are global to the class and do not belong to any object.
(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).
Kips | 46 Copyright @ Kips Learning Pvt. Ltd 2024
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
Question 44:
Assertion (A): Local variables cannot be used outside the body of the method.
s
Reason (R): The local variables are declared while creating the class.
(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.
p
(d) Assertion (A) is false and Reason (R) is true.
Question 45:
Assertion (A): An argument variable is an actual parameter that is used when a function is called.
i
Reason (R): The value of the argument variable is passed to the formal parameter.
(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.
(d) Assertion (A) is false and Reason (R) is true.
K
Question 46:
Assertion (A): Encapsulation keeps data safe from being misused or mishandled.
Reason (R): Overloading is directly related to encapsulation.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 47:
Assertion (A): The lifetime of a local variable is confined to its scope.
Reason (R): The local variables are not accessible outside the method/block.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 48:
Assertion (A): The use of the "final" keyword in Java is limited to variables only.
Reason (R): Applying the "final" keyword to a variable ensures that its value cannot be modified after initialization.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 50:
p
Assertion (A): int d[]={12,15,18,14}; d.length returns 3.
Reason (R): The length property specifies the number of elements in the array.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
i
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 51:
Assertion (A): int [] t={15,23,61,46}; a[4] returns 46.
K
Reason (R): If we try to access an element outside the range of index position 0 to n-1,it results to ArrayIndexOutofBoundsException.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 52:
Assertion (A): In Java, an array containing 5 letters will require 10 bytes for storage
Reason (R): The size of a character datatype is 2 bytes in Java.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 53:
Assertion (A): Linear Search can be applied even if the array is not sorted.
Reason (R): In linear search the search operation begins from first element and goes till the last element.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 54:
Assertion (A): Binary search is faster than linear search.
Reason (R): Binary search takes place on sorted 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).
Kips | 48 Copyright @ Kips Learning Pvt. Ltd 2024
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
Question 55:
Assertion (A): int n[]={2,3,4,5,6};n[1]+n[2]==n[3] will return true.
s
Reason (R): The elements of an array are accessed by the subscript position.
(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.
p
(d) Assertion (A) is false and Reason (R) is true.
Question 56:
Assertion (A): A String is a sequence of characters.
i
Reason (R): Java provides a String class in the java.lang package, and objects of this class can be treated as variables of type
String.
(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.
K
(d) Assertion (A) is false and Reason (R) is true.
Question 57:
Assertion (A): String n=”HARSHIT”; n.charAt(3) returns S.
Reason (R): The charAt() method returns the character present at the specified index position in the String.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 58:
Assertion (A): equals() and compareTo() methods perform the same task.
Reason (R): equals has a return type of boolean and compareTo() returns integer data type.
(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.
(d) Assertion (A) is false and Reason (R) is true.
Question 59:
Assertion (A): “HAPPY BIRTHDAY”.endsWith(“DAY”); returns false.
Reason (R): The return type of endsWith() method is boolean.
(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.
(d) Assertion (A) is false and Reason (R) is true.
s
(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.
(d) Assertion (A) is false and Reason (R) is true.
p
ANSWERS
1. a 2. b 3. a 4. a 5. a 6. a 7. a 8. a 9. c 10. a
11. a 12. a 13. a 14. b 15. a 16. a 17. a 18. a 19. a 20. a
i
21. c 22. d 23. a 24. c 25. a 26. a 27. d 28. a 29. a 30. b
31. a 32. a 33. a 34. c 35. a 36. b 37. a 38. b 39. a 40. a
41. b 42. a 43. a 44. c 45. a 46. c 47. a 48. a 49. a 50. d
51. d 52. a 53. a 54. a 55. d 56. a 57. a 58. d 59. d 60. a
K
Kips | 50 Copyright @ Kips Learning Pvt. Ltd 2024