• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

New Exam Sample Question from Sun.

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is one of the sample question found in the sun's website.
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.)
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();
}
I selected C,D as answers. I tried compiling the option D and it compiled fine. The answer given is C,E. i tried option E and it also ocmpiled fine. am i missing something. I would appreciate if someone could explain this.
Thanks in advance.
Sunitha. S
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sunitha!
How did you manage to compile option D? When I tried it I had an error message: "Can't make a static reference to non-static variable..." InnerOne is declared as static, so it cannot access non-static var d1. But if your variant works, could you post the code?
 
Sunitha Sounderrajan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mapraputa,
You are right. It did give a compilation error. I did not notice that i declared the enclosing class variable as static when i compiled it.
Thanks for your reply.
Sunitha. S
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sunitha, Where did you find the answers to these questions? Is it available there itself?
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shankar,
Question with answers are here: http://suned.sun.com/USA/certification/progsqwa.html
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiled fine for me. That was one of the 6 (yay!) that I got right.
public class OuterClass {
private double d1 = 1.0;
//insert code here
private class InnerOne {
double methoda() { return d1; }
}

abstract class InnerOne2 {
public abstract double methoda();
}
}
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mapraputa Is:
Shankar,
Question with answers are here: http://suned.sun.com/USA/certification/progsqwa.html


Thanks Mapraputa, I had to clear my browser cache to access the new version of this page -- previously it was picking the old set of questions & answers and so I was wondering where the answers are. Thanks anyway.
- Shankar.
 
It's a tiny ad only because the water is so cold.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic