Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is the difference between this() and super()?

Answers were Sorted based on User's Feedback



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

Answer / amol

this() is used to call another constructor of current class based on the argument list....
super() is used to call the constructor of another class or parent class based on the argument list....

Is This Answer Correct ?    1 Yes 0 No

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

Answer / kraja

this() should be first statement in the constructor of the
same class and you cannot call this() in other places

Is This Answer Correct ?    21 Yes 22 No

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

Answer / puneet khanna

this is used to either call another constructor of the same
class whose object is used to call a method; or whose
constructor is being used to instantiate a class.
This refers to the current object whose reference variable
is used to call method or this refers to the current object
in action,
Super refers to the immediate super class, super(); is
itself placed in the constructor of the class whose super
class doesnt has a constructor declared;for consructor
chaining mechanism.

Is This Answer Correct ?    4 Yes 5 No

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

Answer / b.h srinath

This is a keyword that refers to the present/current class.
Usage of this:
1)it can be used to invoke constructor
syntax:this();
example: public sample
{
this(20);
this.display();
}
It is mandatory that,when we are calling constructor through
'this' it must be first statement in that method or constructor.
2)It is used to access data members
example:
this.len=len;
this bth=bth;
3)It is used to access member methods
example:
this.getvalue();
this.setvalue();
super() keyword:
super is a keyword that refers to super class from a subclass.
That means super can refer to super class

i)super class instance variable
example:System.out.println(super.a);
program: class A
{
int a = 30;
}

class B extends B
{

void show()
{
int a=10;
System.out.println("The a Value in super
class is"+super.a);
System.out.println("The a Value in super
class is"+a);
}
public static void main(String[] args)
{
B b=new B();
b.show()
}
}

ii)super class methods
example:super.setvalue();
program:

class one
{

int x,y,s;
one()
{

System.out.println("First went to one default const of super
class");
}

void show(int a,int b)
{

x=a;
y=b;


System.out.println("\n superclass value X is"+x);

System.out.println("\n superclass value Y is"+y);

}
void gets()
{

s=x+y;
}
}
class two extends one
{
int a,b,c;
two()
{

System.out.println("\n second came to default const of
child class");


}

void show()
{
super.gets();
System.out.println("\n baseclass value is"+s);

}
}
class intmet
{
public static void main(String args[])
{
two t=new two();
t.show(2,3);
t.show();
}
}


iii)super class constructor
example:super(a);
super(a,b) and so on

program:


class one
{

int x;
one()
{
System.out.println("First went to one default const of super
class");
}

one(int x)
{
System.out.println("\nas the supre(a)is referd one parameter
const is printed");

this.x=x;

}

void show()
{

System.out.println("\none parameter const value is"+x);

}

}

class two extends one
{

int x,a;
two()
{
System.out.println("\n second came to default const of
child class");
}

two( int a,int b)
{


super(a);

System.out.println("\ntwo const");
x=b;
}
void show()
{

System.out.println("\ntwo parameter const value is"+x);
super.show();

}

}

class const1
{
public static void main(String args[])
{
two t=new two();

two t1=new two(2,3);
t1.show();
}
}

Is This Answer Correct ?    1 Yes 2 No

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

Answer / aman@yahoo.com

this is this() and super is super();

Is This Answer Correct ?    4 Yes 18 No

Post New Answer

More Core Java Interview Questions

Is break statement can be used as labels in java?

0 Answers  


How many bits does a boolean take?

1 Answers  


What are constants?

0 Answers  


What is unicode used for?

0 Answers  


What are the 6 boolean operators?

0 Answers  


what are the diffrences between interface and abstract class?

4 Answers  


can we override the main() method in java????

3 Answers   Vimukti Technologies,


What is private public protected in java?

0 Answers  


What are different types of multitasking?

0 Answers  


What is arraylist class in java?

0 Answers  


What are the restriction imposed on a static method or a static block of code?

0 Answers  


Explain java coding standards for constants?

0 Answers  


Categories