Monday, April 21, 2008

arguments and over loaderrider

COMMAND LINE ARGUNEMTS

class Line
{
public static void main(String arg[])
{
for(int i=0;i System.out.println(arg[i]);
}
}

-----------------------------------------------------------------
DYNAMIC METHOD DISPATCH

class Al
{
void display()
{
System.out.println("Al's display");
}
}
class B extends Al
{
void display()
{
System.out.println("B's display");
}
}
class C extends Al
{
void display()
{
System.out.println("C's display");
}
}
class Dispatch
{
public static void main(String arg[])
{
Al a =new Al();
B b =new B();
C c = new C();
Al r;
r=a;
r.display();
r=c;
r.display();
}
}

---------------------------------------------------------------
METHOD OVERRIDING

class P
{
int a,b;
void getdata(int x,int y)
{
a=x;
b=y;
}
void show()
{
System.out.println("In super class a="+a);
}
}
class B extends P
{
void show()
{
super.show();
System.out.println("In subclass b="+b);
}
}
class Superover
{
public static void main(String args[])
{
B sub =new B();
sub.getdata(4,5);
sub.show();
}
}


OVERLOADING


class Overload
{
void test(int a)
{
System.out.println("Integer Parameter");
}
void test(int a,double b)
{
System.out.println("Two parameters");
}
}
class Overloaddemo
{
public static void main(String a[])
{
Overload d= new Overload();
d.test(10);
d.test(20,4.0);
}
}


VARIABLE LENGTH ARGUMENTS

class VarArgs
{
int test(int ...V)
{
for(int i=0;i System.out.println(V[i]);
System.out.println();
return 0;
}
}
class Vardemo
{
public static void main(String a[])
{
VarArgs av=new VarArgs();
av.test(10,20,60);
av.test(60);
av.test();
}
}



No comments: