File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Majji exam1 Qno2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Majji exam1 Qno2" Watch "Majji exam1 Qno2" New topic
Author

Majji exam1 Qno2

preeti dengri
Ranch Hand

Joined: Nov 30, 2000
Posts: 111
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???
Michael Burke
Ranch Hand

Joined: Jul 29, 2000
Posts: 103
In this case the two assignments have no effect because the two show() methods are declared static.
Andy Boyibolomy
Greenhorn

Joined: Feb 12, 2001
Posts: 11
Hi,
I think you should change the line 2 to q = (Q2) t; so that it runs smoothly.

A.B.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Majji exam1 Qno2