c398s00f

c398s00f - CSc 398 Final Examination Thursday 18 May 2000...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 398 Final Examination Thursday 18 May 2000 >>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<< 1. (10 pts) Assume that thread priority behaves the way the book says they do, and answer the following question TWICE, the first time assuming the underlying machine is a PC and the second time assuming the underlying machine is a Solaris workstation: What is the output of the following code? class One extends Thread{ static String str; One(int n){ super("Thread #"+n); } public synchronized void inc(String s){ str+=s; } public void run(){ inc(getName()+" starts\n"); for(int j=0;j<4000000;j++); inc(getName()+" ends\n"); } public static void main(String s[]){ str=""; One a=new One(1), b=new One(2), c=new One(3); c.setPriority(7); a.start(); b.start(); c.start(); while(str.length()<90); System.out.println("Results:\n"+str); } } PC output: Results: Work Station output: Results:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Thread #1 starts Thread #1 starts Thread #2 starts Thread #1 ends Thread #3 starts Thread #2 starts Thread #3 ends Thread #2 ends Thread #1 ends Thread #3 starts Thread #2 ends Thread #3 ends 2. (10 pts) Explain the differences among the four levels of protection (public, private, etc.) of data members and member functions in Java. Members are public (qualified by the keyword "public"), packaage accessible (no qualifying keyword), protected (qualified by the keyword "protected"), or private (qualified by the keyword "private"). Public members are accessible to any user of the class.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

c398s00f - CSc 398 Final Examination Thursday 18 May 2000...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online