The difference between instance variables and class variables, instance methods and class methods in Java

Transferred from:

Instance variable < ol style = "font family: Verdana, sans serif; font size: 13px;" >< li style="list-style:decimal;text-align:left;"> Instance variables are declared in a class, but outside methods, constructor methods and statement blocks< li style="list-style:decimal;text-align:left;"> When an object is instantiated, the value of each instance variable is determined< li style="list-style:decimal;text-align:left;"> Instance variables are created when the object is created and destroyed when the object is destroyed< li style="list-style:decimal;text-align:left;"> The value of the instance variable should be referenced by at least one method, construction method or statement block, so that the external can obtain the instance variable information through these methods< li style="list-style:decimal;text-align:left;"> Instance variables are visible to methods, constructors, or statement blocks in a class. In general, instance variables should be set to private. Instance variables can be made visible to subclasses by using access modifiers< li style="list-style:decimal;text-align:left;"> Instance variables have default values. The default value of numeric variables is 0, the default value of Boolean variables is false, and the default value of reference type variables is null. The value of a variable can be specified at the time of declaration or in the construction method< li style="list-style:decimal;text-align:left;"> Instance variables can be accessed directly through variable names. But in static methods and other classes, you should use the fully qualified name: obejectreference VariableName。

ClassName. Variablename. TiXing( x, y,255); line-height:1.5 ! important; ">float=== public class ep3_ 9{ void main(String args[]){ TiXing one= new TiXing(1,2,3); System. out. println("one's down is:"+ one. down); TiXing two= new TiXing(4,5,6); System. out. println("one's down is:"+ one. down); System. out. println("two's down is:"+ two. down); System.out.println("TiXing's down is:"+

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>