• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Inheritance from inner Class

Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello !
My Question for the managers of this site
can we inherit a subclass from inner classes if yes than how?
the other question is what are the valid declaration of the inner classes as follows
2. Given:
public class OuterClass {
private double d1 = 1.0;
//insert code here
You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.)
class InnerOne{
public static double methoda() {return d1;}
public class InnerOne{
static double methoda() {return d1;}
private class InnerOne{
double methoda() {return d1;}
static class InnerOne{
protected double methoda() {return d1;}
abstract class InnerOne{
public abstract double methoda();
the third question is whether i have heard from a person given the exam that we also have to write code there e.g how to declare inner class etc.. (this was not in the exam).
waiting for the reply
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can answer number 2 for you. As with methods of classes, you can't access non-static variables with static methods. So with this in mind, you can not access non-static variables from static methods of inner classes either. Makes sense because you don't need an instance of the class to use a static method, so if you don't have an instance of the class, then what does the non-static variable refer to.
So with the above in mind, answer A,B,and D all use static methods and they are trying to access the non-static variable d.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic