0% found this document useful (0 votes)
6 views1 page

Java Module2 Answers

The document provides important questions and answers related to Java programming concepts, including definitions of classes, objects, constructors, and the use of the 'this' keyword. It also covers garbage collection, method overloading, object parameter passing, the static keyword, and the differences between final variables, methods, and classes. Additionally, it explains nested and inner classes in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Module2 Answers

The document provides important questions and answers related to Java programming concepts, including definitions of classes, objects, constructors, and the use of the 'this' keyword. It also covers garbage collection, method overloading, object parameter passing, the static keyword, and the differences between final variables, methods, and classes. Additionally, it explains nested and inner classes in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Module 2 – Important Questions and Answers 1. Define a class and an object.

A class is a blueprint for objects that defines data and methods. An object is an instance of a class
created using the new keyword.
Example:
Car myCar = new Car();

2. What is a constructor?
A constructor initializes objects. It has the same name as the class and no return type.

3. Explain the use of the this keyword.


The this keyword refers to the current object. It is used to access class variables and methods.

4. What is garbage collection in Java?


Garbage Collection automatically removes unused objects to free memory.

5. Difference between declaring and creating an object.


Declaring defines the reference; creating allocates memory using new.
Example:
Car c; (declaration)
c = new Car(); (creation)

6. What is method overloading?


Having multiple methods with the same name but different parameter lists.

7. Explain how objects are passed as parameters.


Objects are passed by reference value; changes inside a method affect the original object.

8. What is the purpose of static keyword?


Static members belong to the class, not instances. Shared among all objects.

9. Difference between final variable, method, and class.


Final variable cannot be changed, final method cannot be overridden, final class cannot be
inherited.

10. What are nested and inner classes?


Nested class is a class within another. Inner class (non-static) can access outer class members.

You might also like