Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic