Java jr int ?s Flashcards

1
Q

What is Method Overloading vs Method Overriding?

A

Method Overloading: That means that with the same class, we can have methods that have the same name but they have to have a different type of parameters or different number of parameters.

Method Overriding: it has to do with inheritance. Where a child class can implement its own version of a method that was inherited from its parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the differences between Heap and Stack Memory?

A

Stack Memory: is the amount of memory allocated for each individual program. It’s a dedicated, fixed memory space for your program.
- it stores the local variables, parameters, and return address, but it’s fixed. So if you have too many method calls or recursive calls and too many items get put into the stack, you’ll eventually run out of space and you have a stack overflow.

Heap Memory: It grows and shrinks as your program runs. It is dynamic memory that grows and shrinks.
- When your program is running and you need to allocate space, you can use the keyword new which is a new object and it allocates the space needed. If you allocate too much space, you can still run out of memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the expected output of the following code segment?

System.out.println(100 + 100 +”KeepOnCoding”);

System.out.println (“KeepOnCoding” + 100 + 100);

A

200KeepOnCoding
KeepOnCoding100100

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are shallow copy and deep copy?

A

Shallow Copy: is a just a set of pointers to the same memory locations. Actually it does not create a real copy so the memory usage is lower.

Deep Copy: An exact copy of the memory segment is created and pointers are set to new memory locations. So theoritically the memory consumption should be twice in this case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Garbage Collector and how does it work?

A

The main objective of the garbage collector is to free up memory space that is not being used anymore. This ensures that memory resources are used efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly