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 is the difference between class forname and new?

538


How many bytes is a url?

558


What is predicate in java?

556


What is a dynamic array java?

507


Does constructor return any value?

572






Is simpledateformat safe to use in the multithreaded program?

537


What is garbage collection? What is the process that is responsible for doing that in java?

645


What is r in java?

589


What is substring in java?

613


What are constructors in java?

563


How do you define a set in java?

502


What do u mean by variable?

559


What is string pool in java?

559


Is Constructor possible in abstract class in java ?

582


Can you explain the meaning of aggregation and composition

565