Sunday, January 1, 2012

Super keyword. in Java

Example



import java.io.*;
class SuperClass
{
int a,b;
SuperClass(int c,int d)
{
a=c;
b=d;
}
void Display()
{
if (a>b)
{
System.out.println(a+"::Greater than::"+b);
}
else
{
System.out.println(b+"::Greater than::"+a);
}
}
}
class SubClass extends SuperClass
{
int e;
SubClass(int f,int g,int h)
{
super(f,g);
e=h;
}
void Display()
{
System.out.println("For 1st two value");
super.Display();
System.out.println("--------------------------------");
System.out.println("For three value");
if (e>super.a && e>super.b)
{
System.out.println(e+"::Greater than::"+super.a+ " "+super.b);
}
else if(super.a>e && super.a>super.b)
{
System.out.println(super.a+"::Greater than::"+e+" "+super.b);
}
else
{
System.out.println(super.b+"::Greater than::"+e+" "+super.a);
}
}
}
public class A404303
{
public static void main(String args[])
throws IOException
{
int p,q,r;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
p=Integer.parseInt(br.readLine());
q=Integer.parseInt(br.readLine());
r=Integer.parseInt(br.readLine());
SubClass s=new SubClass(p,q,r);
s.Display();
}

No comments:

Post a Comment