{"id":699,"date":"2023-03-23T21:50:23","date_gmt":"2023-03-23T13:50:23","guid":{"rendered":""},"modified":"2023-03-23T21:50:23","modified_gmt":"2023-03-23T13:50:23","slug":"Java \u53d8\u91cf","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/699.html","title":{"rendered":"Java \u53d8\u91cf"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

Java \u53d8\u91cf<\/h1>\n<\/p><\/div>\n
\n \u53d8\u91cf\u662f\u5728\u6267\u884cJava\u7a0b\u5e8f\u65f6\u4fdd\u5b58\u503c\u7684\u5bb9\u5668\u3002\u53d8\u91cf\u5206\u914d\u6709\u6570\u636e\u7c7b\u578b\u3002\n <\/div>\n
\n \u53d8\u91cf\u662f\u5185\u5b58\u4f4d\u7f6e\u7684\u540d\u79f0\u3002Java\u4e2d\u5b58\u5728\u4e09\u79cd\u7c7b\u578b\u7684\u53d8\u91cf\uff1a\u5c40\u90e8\u53d8\u91cf\uff0c\u5b9e\u4f8b\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u3002\n <\/div>\n
\n Java\u4e2d\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u6570\u636e\u7c7b\u578b\uff1a\u539f\u59cb\u6570\u636e\u548c\u975e\u539f\u59cb\u6570\u636e\u3002\n <\/div>\n

\u53d8\u91cf<\/h2>\n
\n \u53d8\u91cf\u662f\u5728\u5185\u5b58\u4e2d\u5206\u914d\u7684\u4fdd\u7559\u533a\u7684\u540d\u79f0\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u662f\u5185\u5b58\u4f4d\u7f6e\u7684\u540d\u79f0\u3002\u5b83\u662f\u201cvary+able\u201d\u7684\u7ec4\u5408\uff0c\u8868\u793a\u53ef\u4ee5\u66f4\u6539\u5176\u503c\u3002\n <\/div>\n

Java \u53d8\u91cf_https:\/\/bianchenghao6.com_\u3010Java \u57fa\u7840\u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n
 int data=50; \/\/ \u8fd9\u91ccdata\u662f\u4e00\u4e2a\u53d8\u91cf 
<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u53d8\u91cf\u7c7b\u578b<\/h2>\n
\n Java\u4e2d\u6709\u4e09\u79cd\u7c7b\u578b\u7684\u53d8\u91cf\uff1a\n <\/div>\n

\u5c40\u90e8\u53d8\u91cf<\/span>
\n \u5b9e\u4f8b\u53d8\u91cf<\/span>
\n \u9759\u6001\u53d8\u91cf<\/span>
\n Java \u53d8\u91cf_https:\/\/bianchenghao6.com_\u3010Java \u57fa\u7840\u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

1\uff09\u5c40\u90e8\u53d8\u91cf<\/h3>\n
\n \u5728\u65b9\u6cd5\u4e3b\u4f53\u5185\u90e8\u58f0\u660e\u7684\u53d8\u91cf\u79f0\u4e3a\u5c40\u90e8\u53d8\u91cf\u3002\u60a8\u53ea\u80fd\u5728\u8be5\u65b9\u6cd5\u4e2d\u4f7f\u7528\u6b64\u53d8\u91cf\uff0c\u5e76\u4e14\u7c7b\u4e2d\u7684\u5176\u4ed6\u65b9\u6cd5\u751a\u81f3\u90fd\u4e0d\u77e5\u9053\u8be5\u53d8\u91cf\u5b58\u5728\u3002
\n
\u5c40\u90e8\u53d8\u91cf\u4e0d\u80fd\u7528\u201c static\u201d\u5173\u952e\u5b57\u5b9a\u4e49\u3002\n <\/div>\n

2\uff09\u5b9e\u4f8b\u53d8\u91cf<\/h3>\n
\n \u5728\u7c7b\u5185\u90e8\u4f46\u5728\u65b9\u6cd5\u4e3b\u4f53\u5916\u90e8\u58f0\u660e\u7684\u53d8\u91cf\u79f0\u4e3a\u5b9e\u4f8b\u53d8\u91cf\u3002\u5b83\u6ca1\u6709\u58f0\u660e\u4e3astatic\u3002
\n
\u4e4b\u6240\u4ee5\u79f0\u4e3a\u5b9e\u4f8b\u53d8\u91cf\uff0c\u662f\u56e0\u4e3a\u5176\u503c\u662f\u7279\u5b9a\u4e8e\u5b9e\u4f8b\u7684\uff0c\u5e76\u4e14\u4e0d\u5728\u5b9e\u4f8b\u4e4b\u95f4\u5171\u4eab\u3002\n <\/div>\n

3\uff09\u9759\u6001\u53d8\u91cf<\/h3>\n
\n \u58f0\u660e\u4e3a\u9759\u6001\u7684\u53d8\u91cf\u79f0\u4e3a\u9759\u6001\u53d8\u91cf\u3002\u5b83\u4e0d\u80fd\u662f\u672c\u5730\u7684\u3002\u60a8\u53ef\u4ee5\u521b\u5efa\u9759\u6001\u53d8\u91cf\u7684\u5355\u4e2a\u526f\u672c\uff0c\u5e76\u5728\u8be5\u7c7b\u7684\u6240\u6709\u5b9e\u4f8b\u4e4b\u95f4\u5171\u4eab\u3002\u5f53\u7c7b\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u65f6\uff0c\u9759\u6001\u53d8\u91cf\u7684\u5185\u5b58\u5206\u914d\u4ec5\u53d1\u751f\u4e00\u6b21\u3002
\n
\u7406\u89e3Java\u4e2d\u53d8\u91cf\u7c7b\u578b\u7684\u793a\u4f8b\n <\/div>\n
\n
 class A{ 
int data=50;\/\/instance variable
static int m=100;\/\/static variable
void method(){
int n=90;\/\/local variable
}
}\/\/end of class
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Java\u53d8\u91cf\u793a\u4f8b\uff1a\u4e24\u4e2a\u6570\u76f8\u52a0\n <\/div>\n
\n
 class Simple{ 
public static void main(String[] args){
int a=10;
int b=10;
int c=a+b;
System.out.println<\/span>(c);
}}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n
\n
20<\/code><\/pre>\n<\/p><\/div>\n
\n Java\u53d8\u91cf\u793a\u4f8b\uff1a\u7c7b\u578b\u8f6c\u6362\n <\/div>\n
\n
 class Simple{ 
public static void main(String[] args){
int a=10;
float f=a;
System.out.println<\/span>(a);
System.out.println<\/span>(f);
}}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Java\u53d8\u91cf\u793a\u4f8b\uff1a\u6ea2\u51fa\n <\/div>\n
\n
 class Simple{ 
public static void main(String[] args){
\/\/Overflow
int a=130;
byte b=(byte)a;
System.out.println<\/span>(a);
System.out.println<\/span>(b);
}}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n
\n
130 \n
-126<\/code><\/pre>\n<\/p><\/div>\n
\n Java\u53d8\u91cf\u793a\u4f8b\uff1abyte\u76f8\u52a0\n <\/div>\n
\n
 class Simple{ 
public static void main(String[] args){
byte a=10;
byte b=10;
\/\/byte c=a+b;\/\/Compile Time Error: because a+b=20 will be int
byte c=(byte)(a+b);
System.out.println<\/span>(c);
}}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n
\n
20<\/code><\/pre>\n<\/p><\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Java \u53d8\u91cfzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[],"class_list":["post-699","post","type-post","status-publish","format-standard","hentry","category-java-jichu"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/699"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=699"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/699\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}