0
Why is it wrong and the code is correct !!
public class Namingthread extends Thread { public void run (){ System.out.println("Running!!!"); public static void main(String[] args) { Namingthread t1= new Namingthread(); Namingthread t2= new Namingthread(); System.out.println("Name of t1 is:" + t1 getname()); System.out.println("Name of t2 is:" + t2 getname()); t1.start(); t2.start(); t1.setName("cooding"); System.out.println("After chaning the name of t1..." +t1 getname()); } } }
2 Respostas
+ 4
You are putting hole code inside run() method, even main method.
getname() should be getName(), cause java uses camel case approach for methods naming.
Full code without any errors,
public class Main extends Thread
{
public void run()
{
System.out.println("Running!!!");
}
public static void main(String[] args)
{
Main t1= new Main();
Main t2= new Main();
System.out.println("Name of t1 is:" + t1.getName());
System.out.println("Name of t2 is:" + t2.getName());
t1.start();
t2.start();
t1.setName("cooding");
System.out.println("After chaning the name of t1..." + t1.getName());
}
}
+ 3
Please put Java in thread tags above ☝