Constructor Function: Constructor Function Is A Member Function of A Class Having
Constructor Function: Constructor Function Is A Member Function of A Class Having
Student
Rollno,
Name,
Gender
Department,
semester
No argument constructor function
Parameterized construction function
Display()
Instance Variable Hiding (Use
of “this” Keyword)
• The data members and local variable of a class
may have the same name.
• This phenomena creates a conflict for accessing
the exact data variable.
• The local variable of the function gets
precedence.
• It can be said the local variable of a function
hides the data members of the class
• This key word is used to resolve conflict.
Instance Variable Hiding (Use
of “this” Keyword)
1. class Example{ 1. class demo
2. int x; // data member named x 2. {
3. Void set(int x) // the local 3. Public static void main (String as[ ])
varaibles of the function named 4. {
x 5. Example Ob1=new Example();
4. { 6. Ob1.set(30);
5. //x=x in correct assignment but 7. Ob1.get();
valid.
6. this.x=x; // this key word is 8. }
used to refer current object 9. }
7. } 10.Output:
8. Void get(){ 11.30
9. // no need to use this key word
here
10.System.out.println(“x=“ + x);
11.}}
Garbage Collection.
• Garbage collection (GC) is a form of automatic memory
management.
• The garbage collector, or just collector, attempts to
reclaim garbage, or memory occupied by objects that are no longer
in use by the program.
• A mechanism that periodically checks unreferenced objects in
memory.
• It deallocates the memory allocated to objects.
• Finalization
• Protected void finalize ()
• {
• //Code to be executed prior to the destruction of object of the class
• }
Finalization Example
1. class Example{
6. }