Podcast
Questions and Answers
What happens when an object is dynamically allocated using the new operator?
What happens when an object is dynamically allocated using the new operator?
- The object is immediately destroyed
- The object is automatically deallocated after use
- The object is converted to a primitive data type
- The object remains in memory until it is garbage collected (correct)
What is the purpose of garbage collection?
What is the purpose of garbage collection?
- To convert objects to primitive data types
- To release memory occupied by unused objects (correct)
- To promote byte values to int
- To allocate memory for new objects
What happens to byte, short, and char values in an expression?
What happens to byte, short, and char values in an expression?
- They are promoted to int (correct)
- They are promoted to long
- They are promoted to double
- They are promoted to float
What happens when an int value is assigned to a byte variable?
What happens when an int value is assigned to a byte variable?
What is the result of the expression byte t=100; int p=r * s / t
?
What is the result of the expression byte t=100; int p=r * s / t
?
What happens when a double value is assigned to an int variable?
What happens when a double value is assigned to an int variable?
What is the purpose of the garbage collector in Java?
What is the purpose of the garbage collector in Java?
Why is garbage collection necessary in Java?
Why is garbage collection necessary in Java?
What happens when an object is no longer referenced in Java?
What happens when an object is no longer referenced in Java?
What is the purpose of the finalize() method in Java?
What is the purpose of the finalize() method in Java?
When does garbage collection occur in Java?
When does garbage collection occur in Java?
Why is finalization necessary in Java?
Why is finalization necessary in Java?
What is the primary purpose of the finalize( ) method?
What is the primary purpose of the finalize( ) method?
What is the purpose of the protected specifier in the finalize( ) method?
What is the purpose of the protected specifier in the finalize( ) method?
What is the output of the following code: public class TestGarbage1 { public void finalize() { System.out.println("object is garbage collected"); } public static void main(String args[]) { TestGarbage1 s1=new TestGarbage1(); TestGarbage1 s2=new TestGarbage1(); s1=null; s2=null; System.gc(); } }
What is the output of the following code: public class TestGarbage1 { public void finalize() { System.out.println("object is garbage collected"); } public static void main(String args[]) { TestGarbage1 s1=new TestGarbage1(); TestGarbage1 s2=new TestGarbage1(); s1=null; s2=null; System.gc(); } }
What is the purpose of the System.gc() method?
What is the purpose of the System.gc() method?
What are command-line arguments in Java?
What are command-line arguments in Java?
How are command-line arguments stored in a Java program?
How are command-line arguments stored in a Java program?
Flashcards are hidden until you start studying