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

Answer Posted / ankita jain

super is the first statement of derived class constuctor.

class room
{
int l,b;
room(int x,int y)
{
l = x;
b = y;
}
void area()
{
int a;
a = l*b;
return(a);
}
}
class studyroom extend room
{
int h;
studyroom (int x ,int y, int z)
{
super(x,y)
z = h;
}
int volume()
{
int v;
v = l*b*h;
return(v);
}
}
class sup
{
public static void main(String args[])
{
int ar,vol;
studtroom s=new Studyroom()
ar = s.area();
vol = s.volume();
System.out.println("the area is = "+ar);
System.out.println("the volume is = "+vol);
}
}

Is This Answer Correct ?    24 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the three parts of a lambda expression?

542


How many types of exception can occur in a java program?

545


Can we catch more than one exception in a single catch block?

639


What is charat java?

550


What is polymorphism java example?

556






Can extern variables be initialized?

518


What is class and its types?

548


What is function and its uses?

578


Can I overload to string method

979


Explain creating threads by extending thread class ?

586


What are the parts of methodology?

554


What is difference between array and arraylist in java?

466


What do you mean by mnemonics?

546


What does three dots mean in java?

667


What is string in java?

570