• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

inner classes

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. 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.)
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();
}

the correct answers are c and e.
can anyone xplain the other options as i am a little confused.
are a) and b) wrong cause inner classes cant have static methods ot wht???
and wht abt d) , is it bcause the method is protected or wht ??
or is it bcause the inner class is static ???
pls xplain the reasons for all options if possible, even the correct ones cause i inner classes r very confusin
thx a lot
regards
Kamal
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a & b are wrong because only interfaces or top level classes can have static members.
c is correct as inner/nested classes can be private
d declares a top-level nested class but static references to non-static variables(d here) are not allowed.
e is correct as inner classes can be abstract.
 
Hang a left on main. Then read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic