1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
All Flashcards
What is the value of x
after: int x = 5; x += 3;
?
8
What is the value of y
after: int y = 10; y /= 2;
?
5
What is the output of: String s = "Hello"; System.out.println(s.substring(1, 4));
?
ell
What is the output of: int[] arr = {1, 2, 3}; System.out.println(arr[1]);
?
2
What is the output of: ArrayList<String> list = new ArrayList<>(); list.add("A"); System.out.println(list.get(0));
?
A
What is the output of: int[][] matrix = {{1, 2}, {3, 4}}; System.out.println(matrix[1][0]);
?
3
What is the output: int x = 5; if (x > 3) System.out.print("A"); else System.out.print("B");
?
A
What is the output: for(int i = 0; i < 3; i++) System.out.print(i);
?
012
What is wrong with: String s = "Hello"; s[0] = 'J';
?
Strings are immutable; you cannot change a character at a specific index directly.
What is the output: int x = 5; System.out.println(x++); System.out.println(x);
?
5 6
What is the output: int x = 5; System.out.println(++x); System.out.println(x);
?
6 6
What is the output: String str1 = "hello"; String str2 = new String("hello"); System.out.println(str1 == str2);
?
false
What is the output: String str1 = "hello"; String str2 = new String("hello"); System.out.println(str1.equals(str2));
?
true
What is operator precedence?
The order in which operations are performed (PEMDAS).
What is the purpose of if
statements?
To execute code blocks based on conditions.
What is the purpose of for
loops?
To repeat code a specific number of times.
What is the purpose of while
loops?
To repeat code while a condition is true.
What is the difference between =
and ==
?
=
is the assignment operator, while ==
is the equality check operator.
Why are Strings immutable?
Strings are immutable to improve efficiency and security. Once created, their value cannot be changed.
What is the purpose of instance variables?
Instance variables store the data associated with each object.
What is encapsulation?
Bundling data (instance variables) and methods that operate on the data into a single unit (class), hiding the internal state of an object.
Why use the this
keyword?
To refer to the current object and distinguish between instance variables and parameters with the same name.
Why are array sizes fixed?
For memory efficiency and predictable access times.
What is the purpose of the super
keyword?
Used to call the constructor or methods of the superclass.
What is method overriding?
A subclass providing its own implementation of a method already defined in the superclass.
What is a base case in recursion?
The condition that stops the recursive calls and provides a direct solution.
What is a recursive step in recursion?
The part of the recursive method where the method calls itself with a modified input, moving closer to the base case.
How are arrays applied in real-world scenarios?
Storing lists of data, such as student names, product prices, or sensor readings.
How are ArrayLists applied in real-world scenarios?
Managing a dynamic list of items, such as a shopping cart or a playlist.
How are 2D arrays applied in real-world scenarios?
Representing tables of data, such as spreadsheets, game boards, or image pixels.
How is inheritance applied in real-world scenarios?
Creating a hierarchy of classes, such as different types of vehicles inheriting from a base Vehicle class.
How is recursion applied in real-world scenarios?
Solving problems that can be broken down into smaller, self-similar subproblems, such as searching a file system or parsing a complex data structure.
How are if
statements applied in real-world scenarios?
Controlling program flow based on conditions, such as validating user input or determining which action to take based on the current state.
How are for
loops applied in real-world scenarios?
Iterating through a collection of data, such as processing each item in a list or performing an action a specific number of times.
How are while
loops applied in real-world scenarios?
Repeating an action until a certain condition is met, such as continuously reading data from a sensor until a specific value is reached.