在MyEclipse里建一个类Derived,代码如下:
package p1;class Base
{ public static void sayHello()
{
System.out.println("I am base!");
}}
public class Derived extends Base
{
public static void sayHello()
{
System.out.println("I am derived!");
} public static boolean noticeFinally()
{
try
{
return false;
} finally
{
return true;
}
} public static void main(String args[])
{
Derived instance = new Derived();
instance.sayHello();
System.out.println(instance.notifyAll());
}}
System.out.println(instance.notifyAll());这一句会报错!若没此句,运行还有其它错误.
package p1;class Base
{ public static void sayHello()
{
System.out.println("I am base!");
}}
public class Derived extends Base
{
public static void sayHello()
{
System.out.println("I am derived!");
} public static boolean noticeFinally()
{
try
{
return false;
} finally
{
return true;
}
} public static void main(String args[])
{
Derived instance = new Derived();
instance.sayHello();
System.out.println(instance.notifyAll());
}}
System.out.println(instance.notifyAll());这一句会报错!若没此句,运行还有其它错误.
instance.noticeFinally()
你写错了吧
System.out.println(Derived.noticeFinally());
静态方法直接用类吊样!
public static boolean noticeFinally()
然后noticeFinally()你又加了静态的,你是想调用noticeFinally()吗?
那样的话你直接调用。
改好了再发过来!