File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Use of Private Constructor in Thread Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Use of Private Constructor in Thread Example" Watch "Use of Private Constructor in Thread Example" New topic
Author

Use of Private Constructor in Thread Example

Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
Head First Java, Page 526, typed this up verbatim:



Why is the compiler outputting:



TestThreads.java:32: getAccum() has private access in Accum
Accum a = Accum.getAccum();
^
TestThreads.java:46: getAccum() has private access in Accum
Accum a = Accum.getAccum();
^
2 errors



Please explain


Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Suresh Babu Venkat
Ranch Hand

Joined: Sep 15, 2009
Posts: 30
Thats because the method is private and we cannot access methods which are private from anywhere other than with in the same class


SCJP 6.0 (88%) | SCWCD 5.0 (89%)
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Sandra Bachan wrote:
Why is the compiler outputting:
TestThreads.java:32: getAccum() has private access in Accum
Accum a = Accum.getAccum();
^
TestThreads.java:46: getAccum() has private access in Accum
Accum a = Accum.getAccum();
^
2 errors

Please explain

Since the method getAccum() in the Accum class has the private access, you can't access it beyond that class. That's why you get Compilation Error! change it to public, then it will Compile perfectly!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use of Private Constructor in Thread Example
 
Similar Threads
Threads/Looping: How Can This Be?
TestThreads Code Magnets exercise Head First Java
Why doesn't this code work in Netbeans 7.0?
problem with wait,notify
join() method in Thread doesn't work as expected