• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads and Clonning

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q 1
-----
public class MyRunner implemenrs Runnable{
int x=5;
public void run(){
this.x=10;
}
public static void main(String args[]){
MyRunner r=new MyRunner();
new Thread(r).start();
System.out.println(r.x)
}
}
Ans given : Output can't be determined
But in my openion the output should be 5, bcos after calling the start()
method the call returns to the parent thread. The start() is just to register
the Thread with the Thread Scheduler.
Q 2
-------
public class CloneTest{
public static void main(String args[])
{
int ia[][]={{1,2},null};
int ja[][]=(int[][])ia.clone();
System.out.print((ia==ja)+" ");
System.out.println(ia[0]==ja[0] && ia[1]==ja[1]);
}
}
Object class method
protected Object clone()throws CloneNotSupportedException
I don't understand, why is this compiling........
java.lang.CloneNotSuppertedException extends Exception
this makes it checked exception, checked exceptions must be either caught or
declared by the method in its header (throws clause).
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe arrays are always clonable and the compiler recognizes this.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic