NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

Showing posts with label Interface in java. Show all posts
Showing posts with label Interface in java. Show all posts

Sunday, August 12, 2012

Java program to create user defined thread


class childthread implements Runnable
{
Thread t;
childthread()
{
t=new Thread(this,"hello");
System.out.println("child created");
t.start();
}
public void run()
{
try
{
for(int i=0;i<10;i++)
 {
 System.out.println("child "+i);
 Thread.sleep(500);
 }
}
catch(InterruptedException e)
{}
}
}
class parentthread
{
public static void main(String[] s)
{
 childthread c= new childthread();
try
{
 for(int i=0;i<10;i++)
  {
   System.out.println("main "+i);
   Thread.sleep(1000);
  }
}
catch(InterruptedException e)
{}
}
}

Using of interface in java program


interface x
{
public void area();
}

class y implements x
{
int a,b;
           public void area()
{
a=5;b=7;
System.out.println("Area is "+a*b);c
}
}

 class z implements x
{
int a;
public void area()
{
a=5;
System.out.println("Area of box is "+a*a);
}
}

class inter
{
public static void main(String[] args)
{
y a=new y();
z s=new z();
a.area();
s.area();
}
}