Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2008, 06:01 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default Access modifiers private and public

Hi all, if have been reading from 2 very good sources about using access modifiers (private, public etc). Both sources directly conflict with each other.

One says
"Under no circumstances will a sub class inherit any method or instance variable if it is defined as private in a super class"

and the other source says
"Any private instance variable that has been inherited from a super class can only be accessed indirectly through public setter and getter methods in the super class. If the setters and getters in the super class are defined as private the private instance variables in the sub class will be inaccessible."

Can anyone confirm which is correct.

Many Thanks
Mark


 
Old February 19th, 2008, 11:22 PM
jomet
Guest
 
Posts: n/a
Default

Quote:
quote:Originally posted by markhh



One says
"Under no circumstances will a sub class inherit any method or instance variable if it is defined as private in a super class"

and the other source says
"Any private instance variable that has been inherited from a super class can only be accessed indirectly through public setter and getter methods in the super class. <s> If the setters and getters in the super class are defined as private the private instance variables in the sub class will be inaccessible."</s>

both are same
except some change in strike thorough part
read as 'the super class will be inaccessible'.

if private then variables will be inaccessible in sub class.
for accessing private variables we declare public getters and setters.
Usually by using public methods we will access private variables in sub class.

Cheers,

jomet.
---------------------------------------------
Once you start a working on something,
dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.
 
Old February 19th, 2008, 11:38 PM
jomet
Guest
 
Posts: n/a
Default

hi
check the link also

http://www.uni-bonn.de/~manfear/javaprotection.php


jomet.
---------------------------------------------
Once you start a working on something,
dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.
 
Old February 21st, 2008, 04:56 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Many thanks for your helpful replies,

Mark






Similar Threads
Thread Thread Starter Forum Replies Last Post
X509 public/private key signing and mmc ZeeKoei General .NET 1 January 23rd, 2008 03:52 AM
Friend access modifier acts as private sandeep ASP.NET 2.0 Professional 2 July 19th, 2007 07:35 AM
How to generate public and private keys using RSA mannuvashishta VS.NET 2002/2003 0 March 17th, 2007 10:52 AM
prob with certificate's public/private key [email protected] C# 0 April 5th, 2005 07:18 AM
event handlers declared as private or public ACE2084 ASP.NET 1.0 and 1.1 Basics 3 January 24th, 2005 12:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.