Interview Questions on This Keyword in Java for Freshers

What is this keyword ?

this is reference variable that refers to the current object.


Why use this keyword ?

this keyword can be used to refer current class instance variable and this keyword can also be used to return the current class instance.


What are the uses of this keyword in constructor ?

this can be passed as argument in the constructor call.


Can we call methods using this keyword ?

Yes we can use this keyword to call current class non static methods.


Uses of this keyword with constructor ?

Used to invoke current class constructor.


Difference Between this() and super() ?


Super keyword is always pointing to base class features and this keyword is always pointing to current class features.
this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class.
this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor.


What is the difference between this. (this dot) and this() (this off). ?


this. can be used to differentiate variable of class and formal parameters of method or constructor.
this() can be used to call one constructor within the another constructor without creation of objects multiple time for the same class.


What is difference between super(), super(..), this() and this(..) ?


super() and super(..) are used for establishing the communication between base class and derived class constructor.
this() and this(...) are used for establishing the communication between current class constructor

Related

Latest Spring Interview Questions for Fresher

What is Spring ? It is a lightweight, loosely coupled and integrated framework for developing enterprise applications in java. What are the advantages of spring framework ? Spring framework hav...

IBM AS400 interview Questions and Answers

1.How are the objects stored on AS/400? Ans: All objects are stored on AS/400 in a single level storage. In this method all objects are referenced by one virtual address which is translated in to ...

Objective type C++ Interview Questions for Freshers

1.What does extern mean in a function declaration? It tells the compiler that a variable or a function exists,even if the compiler hasn’t yet seen it in the file currently being compiled. This vari...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item