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

Info icon This 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:
Image of page 1

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

View Full Document Right 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").
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern