Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

program giving compile time errors

 
Venkat Ramsimha
Ranch Hand
Posts: 127
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}
}
 
Ashok Kumar
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic