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

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.
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic