• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Sun Sample queston #2

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
SAMPLE QUESTION 2:
public class OuterClass {
private double d1 = 1.0;
//insert code here }
You need to insert an inner class declaration at line
Which two inner class declarations are valid?(Choose two.)
A. class InnerOne{
public static double methoda()
{return d1;}}
B. public class InnerOne{
static double methoda()
{return d1;}}
C. private class InnerOne{
double methoda()
{return d1;}}
D. static class InnerOne{
protected double methoda()
{return d1;}}
E. abstract class InnerOne{
public abstract double methoda();}
Answer: C,E
Mukti

[This message has been edited by Mukti Bajaj (edited January 22, 2001).]
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following alternatives are not correct because of following reasons
A. Inner class can not declare static members (if they are not final)
B. same as above
C. is true
D. Inner class can not be static. ( It is actually static nested class)
E. is true as inner class can be abstract and can be extended.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Reason given for answer d is not correct "Inner class cannot be declared as static"
The correct reason for that is, if Inner Class is declared as static then it can only access static variables of the enclosing class.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kartik, I don't think you are correct on your reasonings. I'll give it a try.
A. False � d1 is an instances variable, and static methods cannot access instance variables.
B. False � Same as above, the method is static, d1 is not.
C. True � Both are instance variable or methods, neiter are static, everything is ok.
D. False � Inner class is static, so the rules of static methods accessing instance variables applies again. When it comes to static inner classes, think of it as a static method.
E. True � You can have abstract inner classes, and there are no accessibility issues here.
Bill
PS. Thanks Mukti for posting these while the Sun's site is down.
[This message has been edited by bill bozeman (edited January 22, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic