English 中文(简体)
java的静态成员行为
原标题:static members behavior in java
  • 时间:2012-01-13 00:57:40
  •  标签:
  • java

我感到困惑的是,在贾瓦邦的所作所为之下,我知道,在贾瓦,不可能出现静态继承,那么我如何能够呼吁A的B类固定成员?

public  class A {
  static int staticVariable = 5;
  public static void staticMethod(){
  System.out.println("A");
 }
}
public class B extends A{}
public class C {
    public static void main(String[] args) {
      A.staticMethod();
      B.staticMethod();
      System.out.printf("A s int value %d and B s int value is %d",A.staticVariable,B.staticVariable);
    }
}

产出:

A
A
A s int value 5 and B s int value is 5
最佳回答

你在这里做的不是“法定继承”,而是指简单旧的名称(在汇编时间)。 这样做是为了使你能与B一道获得名字,除非B本身界定姓名。

问题回答

例见static members is<>em>s>。 缩略语

For class methods, the runtime system invokes the method defined in the compile-time type of the reference on which the method is called. For instance methods, the runtime system invokes the method defined in the runtime type of the reference on which the method is called.

Read this article for more details: http://krsethur.wordpress.com/2005/12/15/static-method-inheritance/

我认为静态方法/可变性与使用OP语言一样。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...