Java jr int ?s Flashcards
What is Method Overloading vs Method Overriding?
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.
What are the differences between Heap and Stack Memory?
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.
Explain the expected output of the following code segment?
System.out.println(100 + 100 +”KeepOnCoding”);
System.out.println (“KeepOnCoding” + 100 + 100);
200KeepOnCoding
KeepOnCoding100100
What are shallow copy and deep copy?
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.
What is the Garbage Collector and how does it work?
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.