• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
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);
}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic