What are the steps to create an object?

  1. Declare a variable of the class type. 2. Use the new keyword followed by the class constructor. 3. Assign the result to the variable.
Flip to see [answer/question]
Flip to see [answer/question]

All Flashcards

What are the steps to create an object?

  1. Declare a variable of the class type. 2. Use the new keyword followed by the class constructor. 3. Assign the result to the variable.

What are the steps to traverse an array?

  1. Use a for loop or enhanced for loop. 2. Initialize a counter (if using a for loop). 3. Access each element using its index.

What are the steps to traverse a 2D array?

  1. Use nested for loops. 2. The outer loop iterates through rows. 3. The inner loop iterates through columns.

What are the steps in calling a superclass constructor?

  1. Use the super() keyword in the subclass constructor. 2. Provide the necessary parameters that match the superclass constructor's signature. 3. This call must be the first statement in the subclass constructor.

What are the steps to implement recursion?

  1. Identify the base case(s). 2. Define the recursive step, calling the method itself with a modified input. 3. Ensure the recursive step moves towards the base case.

What are the differences between arrays and ArrayLists?

Arrays: Fixed size, primitive and object types, length property. ArrayLists: Dynamic size, object types only, methods like add(), remove(), size().

What are the differences between == and .equals() for Strings?

==: Compares object references. .equals(): Compares the content of the strings.

What are the differences between for and while loops?

for: Used when the number of iterations is known. while: Used when the number of iterations is unknown, and depends on a condition.

What are the differences between method overloading and method overriding?

Overloading: Multiple methods with the same name but different parameters in the same class. Overriding: A subclass providing a different implementation for a method already defined in its superclass.

What are the differences between x++ and ++x?

x++: Post-increment, returns the original value then increments. ++x: Pre-increment, increments then returns the new value.

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.