• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Marcus Green Exam 2 questions

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody clarify? Thanks in advance.
Q57:
Which of the following statement are true?
1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the private modifier
3) A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated
answer given is 3 and 4.Is 4 correct? I think I can instantiate an interface, like the code of question 50 in the same exam as quoted below:
////////////////////////////////////////
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace(); //is this an instance?
}
}
/////////////////////////////////
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
CFace in this question is a class which implements the interface IFace. You cannot create an instance of the IFace interface itself.
I think it's ok to assign an instance of CFace to an IFace reference, since CFace "is an" IFace by implementing it. It's simply casting up the heirarchy.
But if you were to try IFace iface = new IFace(); you would get an error.
Hope that makes sense!
--liz

------------------
Elizabeth Lester
SCJP Dreamin'
[This message has been edited by Elizabeth Lester (edited September 27, 2001).]
[This message has been edited by Elizabeth Lester (edited September 27, 2001).]
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have an variable declared of the interface type but the rule is it should refer only to the class that implemented it .
IFace o2 = new CFace();
IFace is the interface & CFace is the class implementing it.
I hope I explained to your satisfaction :-)

Originally posted by Tony Xu:
Can anybody clarify? Thanks in advance.
Q57:
Which of the following statement are true?
1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the private modifier
3) A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated
answer given is 3 and 4.Is 4 correct? I think I can instantiate an interface, like the code of question 50 in the same exam as quoted below:
////////////////////////////////////////
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace(); //is this an instance?
}
}
/////////////////////////////////


 
Tony Xu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I see.
Really a great SJCP website!
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone think this question is misleading, I think of the concept of instantiating something is creating an instance with a call to new (which I think is fair to say you cannot do with an Interface), Feedback much appreciated as I want my questions to test knowlege and not to test the details of interpretations of concepts.
Marcus
------------------
http://www.jchq.net Mock Exams, FAQ, Tutorial, Links, Book reviews
=================================================
Almost as good as JavaRanch
=================================================
 
Elizabeth Lester
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcus,
I personally think the question is a good one. It examines our understanding of the difference between a reference and an instance. This discrimination is critical for String/gc questions like we are seeing discussed so much.
A difference that we should be pretty clear on to do well on the exam and in our future Java adventures!

Thanks for your exams,
Liz
------------------
Elizabeth Lester
SCJP Dreamin'
[This message has been edited by Elizabeth Lester (edited September 28, 2001).]
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic