大家如果都不测试.说出程序的执行流程,及输出结果,并分析原因.
package cm.image.icon;
import javax.swing.*;
import java.awt.*;
/**
* <p> Title: </p>
*
* <p> Description: </p>
*
* <p> Copyright: Copyright (c) 2007 </p>
*
* <p> Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Client {
private void test(JFrame frame) {
System.out.println( frame.getClass().getName() );
}
private void test(Frame f) {
System.out.println( f.getClass().getName() );
}
public static void main(String args[]) {
Client c = new Client();
Frame f1 = new JFrame();
c.test(f1 );
JFrame f2 = new JFrame();
c.test(f2 );
}
}
------解决方案--------------------
LZ能给解释一下吗??? 没弄明白为什么结果是这样的.......
------解决方案--------------------
学习 up up 正在学swing 呵呵 初学 能给解释一下吗?? 明天上课我好吹一下 .....
------解决方案--------------------
JFrame继承自Frame,有什么不对么?
------解决方案--------------------
我以为是
java.awt.Frame
javax.swing.JFrame
没想到是:
javax.swing.JFrame
javax.swing.JFrame
和下面这个例子一样:
class People
{}
class Student extends People
{}
public class Client
{
public static void main(String args[])
{
People p1 = new Student();
System.out.println( p1.getClass().getName() );
Student p2 = new Student();
System.out.println( p2.getClass().getName() );
}
}
结果:
execices.Student
execices.Student
------解决方案--------------------
看一下就知道了
public final Class <? extends Object> getClass()
Returns the runtime class of an object. That Class object is the object that is locked by static synchronized methods of the represented class.
Returns:
The java.lang.Class object that represents the runtime class of the object. The result is of type Class <? extends X> where X is the erasure of the static type of the expression on which getClass is called.
------解决方案--------------------
javax.swing.JFrame;