Topics Index

this and super

If you need explanation Read this topic

If you need Answer Take test on this topic

this and super
Which of the following is incorrect?

X: this() is used to invoke a constructor of the same class.
Y: super() is used to invoke a superclass constructor.
A. X only
B. Y only
C. Both are correct
D. Both are incorrect
Topic: Inheritance And Constructors In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans c.this() can be used to invoke current class constructor.super() used to invoke immediate parent class.   If a super-class contains two or moreconstructors and there is no defaultconstructor, it is required that the sub-classconstructor specifically call the requiredsuper-class constructor using superkeyword.

Posted by Maheshwari Natarajan    2015-02-18 04:39:42

Ans is C.
this() is used to invoke the constructor of the same class...which is helpful to create the communication between constructors of same class...
super() is used to invoke a super class constructor.. which is helpful to get the access of parent class constructor... By default compiler will call super class default constructor.. we need to be careful if the super class doesn't have no-arg constructor, at that time we need to call a specific super class constructor explicitly using super keyword...

Posted by Gopinath Manchikanti    2015-02-18 07:47:46

Ans is c both are correct

This() - this keyboard is used to call the constructor of same class.

--- super (): it is used to call constructor of parent class. But this should be the first statement in constructor of child class. Even if you don't write it ,it is by default embedded by compiler into the code and constructor of parent class is called before the constructor of child class.

both are correct.

Posted by Mânïshå Mùlchåndânï    2015-02-18 14:06:32

This dose is now closed and the winners are Maheshwari Natarajan,  for 'First Correct Comment', Gopinath Manchikanti, Mânïshå Mùlchåndânï,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is ?????????? ?????. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-02-19 04:01:13

© meritcampus 2019

All Rights Reserved.

Open In App