ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
What is the use of ?this??
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is the use of ?this??
Answer
# 1
'this'  operator is used to denote the current working 
object. 

 EX:
      Class student{
        public student(){
             this.addStudent();
        }
        public void addStudent(){
               //     to do code here
        }
        public static void main(String args[]){
           new student();
        }
      }
   
    'this' in the constructor is used to denote the current 
working object student...
 
Is This Answer Correct ?    0 Yes 0 No
Ashokmail
[Uss]
 
  Re: What is the use of ?this??
Answer
# 2
The 'this' keyword in Java has the following uses:

1. To resolve ambiguity where a local variable hides a class
member. Example:

class MyClass {
    private int value;

    public MyClass( int value ) {
        // local variable 'value' hides class field 'value'
        this.value = value;
    }
}

2. To invoke one constructor overload from another. Example:

class MyClass {
    private int value;

    public MyClass( int value ) {
        this.value = value;
    }

    public MyClass() {
        // invoke MyClass( int value )
        this( 0 );
    }
}

3. To pass the current object instance as a parameter to a
method. Example:

class MyClass {
    private int value;

    public MyClass( int value ) {
        this.value = value;
        // pass current instance as a parameter to the method
        displayValue( this );
    }

    public static void displayValue( MyClass mc ) {
        System.out.println( "Value = " + mc.value );
    }
}

4. To invoke an outer class's non-static method from a
non-static inner class. Example:

class MyOuterClass {
    
    class MyInnerClass {
        public MyInnerClass() {
            // call the outer class's method
            MyOuterClass.this.displayText( "Inner instance
created" );
        }
    }

    public void displayText( String text ) {
        System.out.println( text );
    }
}
 
Is This Answer Correct ?    1 Yes 0 No
Ranganathkini
 
 
 
  Re: What is the use of ?this??
Answer
# 3
this is used to refer the current instance
 
Is This Answer Correct ?    0 Yes 0 No
Ravikiran
 
  Re: What is the use of ?this??
Answer
# 4
this:
a. It call the overloaded(same class only)constructor
b.refer the current object.
c.U cant use 'this' in static method.
 
Is This Answer Correct ?    0 Yes 0 No
Vijayakumar Chinnasamy
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is the need of the Ajax? iFlex5
What is the root class for all Java classes?  4
Is it possible to create Userdefined Unchecked Exception also?If Yes, give an example?  2
how can you retrive information from database by using hashmap/arraylist ,plz explain with example briefly? Satyam1
We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.  2
wHAT IS DEFAULT SPECIFIER IN JAVA wHAT IS DEFAULT CONSTRUCTOR IN JAVA wHAT IS DEFAULT METHOD IN JAVA IBM10
What is the difference between overloading and overriding a function? Infosys7
Different types of modifiers? RoboCom3
can anyone explain me the concept of autoboxing?  3
How to decrease number of hashings in has  1
How do you relate a Interface to a Class? Tell me in Detail?  4
How can you take string into InputStream?  3
What do u mean by method and also contructer in java ?  3
what is the difference between AWT and SWING what is the advantage of using swing?  3
How can final class be used? Wipro2
What is the difference between array and arraylist? what is the difference between arraylist and linkedlist? EDS4
How to deprecate a method? Show it with proper example. Plz give the answer of this.Thanx in advance. mail me: tanzeem.akhtar@gmail.com  1
What is the difference between set and list?  3
If I have 1000 objects and my requirement is to sort them quickly, then which collection would you recommend and why? KPIT3
what is tempplate pattern RBS4
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com