Makarand Akdar

Greenhorn
+ Follow
since Feb 03, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Makarand Akdar

What will be the output when you compile and execute the following program.

////////////////////////////////////////////
class Base
{
void test() {
System.out.println("Base.test()");
}

}
////////////////////////////////////////////
public class Child extends Base {

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

static public void main(String[] a) {
Child anObj = new Child();
Base baseObj = (Base)anObj;
baseObj.test();
}
}

Select most appropriate answer.

a) Child.test()
Base.test()
b) Base.test()
Child.test()
c) Base.test()
d) Child.test()

The answer given is d)
I think c) is the right answer.
Please help.
-Thanks
Which of the following lines will compile when added to the Child class
without making any other changes.
public class Child {
void test() {
System.out.println("Child.test()");
}
}
Select all valid answers.

a) abstract void test_a (int i);
b) abstract void test_b (int i) { };
c) abstract void test ();
d) final void test_d (int i);
e) native void test_e (int i);
f) private abstract void test_f(int i);

The answer given is e)
Whats wrong with d)
-Thank you all...
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