Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

inner class questoin  RSS feed

 
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
 
Ranch Hand
Posts: 2410
  • 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.
 
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!