• 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
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Mock Exam question

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Question 6:
Answer: B and C are correct.

Question 7:
Answer: A and C are correct.

I find both questions contracdicting themselves... Why in Q 6 A is not right and in Q 7 A is right
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you declare a constructor, the compiler does not declare a no-arg constructor. So, in Q6, A will fail due to the absence of a no-arg constructor.
In Q7, if public Test(int j) is invoked then the superclass's no-arg constructor will be invoked. So, either you must declare a no-arg constructor in Base or invoke a superclass's arg constructor from Test.
Just remember that for every constructor in a subclass which does not call super, the compiler will expect to see a no-arg constructor in the superclass.
Incidentally, I invariably declare a constructor in my programs, it makes life much easier.
[ April 15, 2003: Message edited by: Roger Chung-Wee ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi preeti,
Q6:
the rule is:

default constructor is one with no argument.
So where is Test()?
NO. Therefore new Test() is wrong.
Q7:
What is the code for Base class? Without it we cannot judge Base() is correct or not.
 
preeti khane
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger ,

" In Q7, if public Test(int j) is invoked then the superclass's no-arg constructor will be invoked. So, either you must declare a no-arg constructor in Base or invoke a superclass's arg constructor from Test."


Q6 says that B is right... According to your above statement, If B is right then it it will invoke the the superclass's no-arg constructor ... So if they are correctly compiled, we assume that Test() exists and we shud be able to call option A: new Test() for Q6
I feel that without the Base class definition in Q6 there is no real way to determine correctness of the answers
Am I right in making these assumptions? Can anyone give me concrete explanations as to why the answers are what they are
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charles!


Q7:
What is the code for Base class? Without it we cannot judge Base() is correct or not.


We don't need Base class code to decide this. Think about it this way.
Base class will have a non argument constructor because of line numbered 5. Right??
This implies that compiler will not provide implicit default constructor when reqd. One has to explicitly provide it.
Now, what will the constructor Test(int j) call when it does not have an explicit call to base class constructor?? Definitely! default constructor. So,compiler will complain if we don't provide Base class' default constructor explicitly.
Hope, i made myself clear.
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic