• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

program giving compile time errors

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,anybody please provide the solution as why the below given program is giving compile time errors

public class A45 extends Thread
{
public void run()
{
synchronized (this)
{
try
{
wait(5000);
}
catch (InterruptedException ie)
{
}
}
}
public static void main(String[] args)
{
A45 a1 = new A45();
long startTime = System.currentTimeMillis();
a1.start();
System.out.print(System.currentTimeMillis() - startTime + ",");
try
{
a1.join(6000);
}
catch (InterruptedException ie)
{
}
System.out.print(System.currentTimeMillis()-startTime);
}
}
}
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a problem with the braces.Always indent your code fro better redability.Heres the code that will compile correctly

public class A45 extends Thread
{
public void run()
{
synchronized (this)
{
try
{
wait(5000);
}
catch (InterruptedException ie)
{
}
}
}

public static void main(String[] args)
{
A45 a1 = new A45();
long startTime = System.currentTimeMillis();
a1.start();
System.out.print(System.currentTimeMillis() - startTime + ",");
try
{
a1.join(6000);
}
catch (InterruptedException ie)
{
}
System.out.print(System.currentTimeMillis()-startTime);
}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic