Forums Register Login

Majji exam1 Qno2

+Pie Number of slices to send: Send
look for the following code
class Test
{
static void show()
{
System.out.println("Show method in Test class");
}
}
public class Q2 extends Test
{
static void show()
{
System.out.println("Show method in Q2 class");
}
public static void main(String[] args)
{
Test t = new Test();
t.show();
Q2 q = new Q2();
q.show();

t = q;// --------------------line 1
t.show();
q = t; //--------------------line 2
q.show();
}
}
prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Q2 class"
what effect does line 1 and line 2 make on the result???
+Pie Number of slices to send: Send
In this case the two assignments have no effect because the two show() methods are declared static.
+Pie Number of slices to send: Send
Hi,
I think you should change the line 2 to q = (Q2) t; so that it runs smoothly.
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 697 times.
Similar Threads
Tips,oneliner Just before the SCJP Exam
Doubt in the code.
Question
plz help
assignment
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:10:01.