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

mock exam Jargon(sarga)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
public class Child extends Base {

Child(int i) { test (); }

Child(float f) { this ((int)f); }

void test() {
System.out.println("Child.test()");
}

static public void main(String[] a) {
new Child(10.8f).test();
}
}
Select most appropriate answer.

a) Child.test()
Child.test()
b) Compilation Error: No default constructor ( constructor matching Base())
found in class Base.
c) Runtime Error: No default constructor ( constructor matching Base())
found in class Base.
d) Compilation Error: Cannot call this() from a constructor.
The Answer to this question in given as ...a)
Why does Child.test() print twice ?
-Thanks
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, where's the base class man?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Makarand Akdar:
Hi friends,
public class Child extends Base {

Child(int i) { test (); }

Child(float f) { this ((int)f); }

void test() {
System.out.println("Child.test()");
}

static public void main(String[] a) {
new Child(10.8f).test();
}
}
Select most appropriate answer.

a) Child.test()
Child.test()
b) Compilation Error: No default constructor ( constructor matching Base())
found in class Base.
c) Runtime Error: No default constructor ( constructor matching Base())
found in class Base.
d) Compilation Error: Cannot call this() from a constructor.
The Answer to this question in given as ...a)
Why does Child.test() print twice ?
-Thanks


test() is called twice.
1. Child(int i) { test (); }
2. new Child(10.8f).test();
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
priya - in this code there is no ref to the superclass(base)
so can we assume that the int constructor is making a call (super) to the superclass and that the superclass has to have a int constructor
OR
that the superclass has a no args constructor , hence there is no problem of super
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic