Very nice discussion, Adrian! Mark
-----Original Message----- From: Adrian Janssen Sent: Friday, July 11, 2003 4:01 AM To answer question 1: You can hide ancestor variables by declaring a variable in a descendant class with the same name. However the ancestor class's variable is still accessible via the super keyword. Hence this is generally NOT considered overriding because if you call a method in the ancestor from the descendant class, the ancestor method will use the old variable. Here is an excerpt from the language specification that explains it more completely: 8.3.3.1 Example: Hiding of Class Variables The example: class Point { static int x = 2; } class Test extends Point { static double x = 4.7; public static void main(String[] args) { new Test().printX(); } void printX() { System.out.println(x + " " + super.x); } } produces the output: 4.7 2 because the declaration of x in class Test hides the definition of x in class Point, so class Test does not inherit the field x from its superclass Point. Within the declaration of class Test, the simple name x refers to the field declared within class Test. Code in class Test may refer to the field x of class Point as super.x (or, because x is static, as Point.x). If the declaration of Test.x is deleted: class Point { static int x = 2; } class Test extends Point { public static void main(String[] args) { new Test().printX(); } void printX() { System.out.println(x + " " + super.x); } } then the field x of class Point is no longer hidden within class Test; instead, the simple name x now refers to the field Point.x. Code in class Test may still refer to that same field as super.x. Therefore, the output from this variant program is: 2 2 To answer Question 2 For case 2 if the servlet is unsyncronized then there is generally only one instance and there are multiple threads running through it, one per concurrent request. For case 1 the servlet specification does specify exactly how the SingleThreadModel should be implemented, and it will behave differently in different servlet containers. I also have haeard and read that it is going to be removed from the servlet specification in the future and in general its use strongly discurouged. To answer Question 3 An inner class has all the rights its "outer" or containing class has. Hence the two inner classes may call each others private methods because the containing class is allowed to. If you consider that access mofiers are provided so that you can limit what "other" programmers (actually other classes, you should consider yourself as a different programmer when coding another class) can access, and if you acknowledge that a class, including inner classes, is generally only written by one programer then it is sensible that they can access each others private methods. Otherwise you would just be hiding things from yourself. Cheers Adrian > -----Original Message----- > From: purushottam krishna hegde [SMTP:[EMAIL PROTECTED] > Sent: 11 July 2003 07:08 > To: [EMAIL PROTECTED] > Subject: private access specifier > > hi all, > there r couple of of questions. > Question 1) > here is one interview question. > > Can u override variables? > pl explain > Question 2)can anybody explain me how a servlet containerhandles > multiple request from diff clients when > case a)there is only one instance in pool and there r 1000 requests > sub case1: if servlet method is synchronised.(SingleThreadModel > interface) > sub case2: non synchronised service > > case b)there r 100 instance of servlet in pool and 1000 requests and > non synchronised service > > as wrox book says > it can adopt 2 methods. > 1)instance pooling > 2)request serialization > bot for syn service method > is this right? > > > Question 3) > here is some code which tests the private access specifiers class > inner_one's constructor is private and one of its method is private it > is still accessible by inner_two how? > is private access specifier does't apply to inner classes? > public class private_test{ > public class inner_one{ > private inner_one(){ > } > private void inner_amethod(){ > } > } > public class inner_two{ > inner_two(){ > inner_one in1 = new inner_one(); > in1.inner_amethod(); > } > } > } > > > _____ > > Do you Yahoo!? > SBC Yahoo! DSL > <http://pa.yahoo.com/*http://rd.yahoo.com/evt=1207/*http://promo.yahoo > .com > /sbc/> - Now only $29.95 per month! -- It is the strict policy of Truworths that its e-mail facility and all e-mail communications emanating therefrom, should be utilised for business purposes only and should conform to high professional and business standards. Truworths has stipulated certain regulations in terms whereof strict guidelines relating to the use and content of e-mail communications are laid down. The use of the Truworths e-mail facility is not permitted for the distribution of chain letters or offensive mail of any nature whatsoever. Truworths hereby distances itself from and accepts no liability in respect of the unauthorised use of its e-mail facility or the sending of e-mail communications for other than strictly business purposes. Truworths furthermore disclaims liability for any unauthorised instruction for which permission was not granted. Truworths Limited accepts no liability for any consequences arising from or as a result of reliance on this message unless it is in respect of bona fide Truworths business for which proper authorisation has been granted. Any recipient of an unacceptable communication, a chain letter or offensive material of any nature is requested to notify the Truworths e-mail administrator ([EMAIL PROTECTED]) immediately in order that appropriate action can be taken against the individual concerned. ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html