• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

inner class questoin

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given:
1. public class OuterClass {
2. private double d1 = 1.0;
3. //insert code here
4. }

You need to insert an inner class declaration at line2. Which two inner class declarations are valid? (Choose Two)
A. static class InnerOne {
public double methoda(){return d1;}
}
B.static class InnerOne {
static double methoda(){return d1;}
}
C.private class InnerOne {
public double methoda(){return d1;}
}
D.protected class InnerOne {
static double methoda(){return d1;}
}
E.public abstract class InnerOne {
public abstract double methoda();
}


ths answer is C,E WHY?

TKS
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shiao Kung Chux:
Given:
1. public class OuterClass {
2. private double d1 = 1.0;
3. //insert code here
4. }

You need to insert an inner class declaration at line2. Which two inner class declarations are valid? (Choose Two)
A. static class InnerOne {
public double methoda(){return d1;}
}
B.static class InnerOne {
static double methoda(){return d1;}
}
C.private class InnerOne {
public double methoda(){return d1;}
}
D.protected class InnerOne {
static double methoda(){return d1;}
}
E.public abstract class InnerOne {
public abstract double methoda();
}


ths answer is C,E WHY?

TKS




In A,B and D, you can't access a non-static variable from a static context.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inner Class is a non-static member of a class defined without keyword static.

With this u can eliminate A and B

Inner classes can't have static members

With this you can eliminate D

So, u are left with C and E
reply
    Bookmark Topic Watch Topic
  • New Topic