• Post Reply Bookmark Topic Watch Topic
  • New Topic

inner class questoin  RSS feed

 
Shiao Kung Chux
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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.
 
Sreeni Reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!