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 Posted / jyotshna pardhia
In a constructor if we call super and this in
the same class than we will get compile time error saying
that call to this() must be the first statement of the
construtor OR call to super() must be the first statement
of the constructor.So it is not possible to call
both in the same one.
Ex:-1
class Test
{
Test()
{
super();
this();
systm.out.println("hello Jyotshna");
}
}
error:- call to this() must be the first statement of
constructor.
Ex:-2
class Test
{
Test()
{
this();
super();
systm.out.println("hello Jyotshna");
}
}
error:- call to super() must be the first statement of
constructor.
Thanks & Regards
jyotshna
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
Explain the importance of finally block in java?
Difference between Linked list and Queue?
How are this() and super() used with constructors in java programming?
Why heap memory is called heap?
Why array is used in java?
What exceptions occur during serialization?
Can I declare a class as private?
Is arraylist a class in java?
Discuss different types of errors that generally occur while programming.
What are the core java topics?
How do you stop a thread in java?
What does jre stand for?
What is compareto?
How to create a custom exception?
What is meant by method overriding?