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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
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
in a constructor what happen if u call super and this in 
the same class? i know  that it is not possible to call 
both in the same one? if we call what will happen?
 Question Submitted By :: Dsureshkumar28
I also faced this Question!!     Rank Answer Posted By  
 
  Re: in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
Answer
# 1
it wil giv an exception -compiler exception
 
Is This Answer Correct ?    1 Yes 1 No
Srikant Bhat
 
  Re: in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
Answer
# 2
It will run fine with no exception here is the example :

public class CheckException extends Thread{
	public CheckException(){
		super.start();
		this.start();
	}
@Override
public synchronized void start() {
	// TODO Auto-generated method stub
	super.start();
}
}
 
Is This Answer Correct ?    2 Yes 1 No
Ajay Dhingra
 
 
 
  Re: in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
Answer
# 3
wont there be any stack overflow?
 
Is This Answer Correct ?    1 Yes 0 No
Srikant Bhat
 
  Re: in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
Answer
# 4
The question clearly specifies "what happen if u _CALL_
super and this in the same class"

By call, probably, they mean:
   this();  /*Invoking the constructor*/
   super(); /*Invoking the parent class's constructor*/

I think the right answer is that it will raise a compiler
exception. Such a program will not compile.
 
Is This Answer Correct ?    1 Yes 0 No
Agile Being
 
  Re: in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
Answer
# 5
We can't give both super() and this()in a constructor,
because both of these statements must be the first
statements in constructor. if you give super() as the first
statement then compiler error will come with this() call.
and vice versa.
but you can call the members with both super and this in a
constructor. here is the code.
class Base
{
	Base()
	{
		System.out.println("Base constructor");
	}
	void m1()
	{
		System.out.println("m1 of Base");
	}
}
class Derived extends Base
{
	Derived()
	{
		super();//it is ok.
		this();//raises compiler error 
      //but we can call the members with super and this 
            super().m1();//make sure that   super()in      
line must be marked comment
            this().m1();
	System.out.println("Derived constructor");
		}
	void m1()
	{
		System.out.println("m1 of Derived");
	}
	public static void main(String[] args) 
	{
	Derived d=new Derived();
	}
}
it works out
 
Is This Answer Correct ?    3 Yes 1 No
Madhu
 
  Re: in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
Answer
# 6
No it doesn't work I have just tested
 
Is This Answer Correct ?    1 Yes 0 No
Srisanjana
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Keywords in Exceptions?  1
Hi Friends, can you explain instance in java. In general instance means "occurence of something" . In java what is instance.  2
What is a J2EE component? List out all the component? Adobe2
why to use transient variables when static variables can be used for Serialization  3
what are the different access specifiers that can be used by interfaces and abstract classes? can anyone give me detailed description on this  7
what are depricated methods in threads and explain the lifecycle methods  5
Functionality of JVM? Infosys4
How to do validation of the fields in any project ?  2
How do you set security in applets? Wipro1
Name the methods that used to get and set the text label displayed by a Buttonobject?  1
What is run-time class and system class? what is their purpose?  1
Explain the relationship between the Canvas and Graphics class?  1
What is the difference between C++ & Java? Syntel21
What is the default initialized value of String type variable?  3
In which way does a Primitive data type is passed ? Sun-Microsystems2
How to print nodes of a Binary tree? TCS1
what release of java technology are currently available what do they contain?  1
Can a double value be cast to a byte?  3
Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result? 1 Compilation fails because of an error in line 25. 2 The code runs with no output. 3 An exception is thrown at runtime. 4 Compilation fails because of an error in line 20.  1
What is Interface? BMC5
 
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