毕业设计网站源码,石家庄建站工具,wordpress上传设置,网站不兼容怎么办啊局部变量和成员变量的区别
区别1#xff1a;代码中位置不同 成员变量#xff1a;类中方法外定义的变量 局部变量#xff1a;方法中定义的变量 代码块中定义的变量
区别2#xff1a;代码的作用范围 成员变量#xff1a;当前类的很多方法 局部变量#xff1a;当前一…局部变量和成员变量的区别
区别1代码中位置不同 成员变量类中方法外定义的变量 局部变量方法中定义的变量 代码块中定义的变量
区别2代码的作用范围 成员变量当前类的很多方法 局部变量当前一个方法当前代码块 区别3是否有默认值 成员变量有 局部变量没有
引用数据类型 null
区别4是否要初始化 成员变量不需要不建议初始化后续使用的时候再赋值即可 局部变量一定需要不然直接使用的时候报错 区别5内存中位置不同 成员变量堆内存 局部变量栈内存
区别6作用时间不同 成员变量当前对象从创建到销毁 局部变量当前方法从开始执行到执行完毕 1.package com.msb;
2.
3./**
4. * Auther: msb-zhaoss
5. */
6.public class Student {
7. byte e;
8. short s;
9. int c ;//成员变量在类中方法外
10. long num2;
11. float f ;
12. double d;
13. char ch;
14. boolean bo;
15. String name;
16. public void study(){
17. int num 10 ; //局部变量在方法中
18. System.out.println(num);//10
19. //int num ;重复命名出错了
20. {
21. int a;//局部变量在代码块中
22. }
23. int a;
24. if(13){
25. int b;
26. }
27. System.out.println(c);
28. }
29. public void eat(){
30. System.out.println(c);
31. }
32.
33. //这是一个main方法是程序的入口
34. public static void main(String[] args) {
35. Student s new Student();
36. System.out.println(s.c);
37. System.out.println(s.bo);
38. System.out.println(s.ch);
39. System.out.println(s.d);
40. System.out.println(s.e);
41. System.out.println(s.f);
42. System.out.println(s.name);
43. System.out.println(s.num2);
44. System.out.println(s.s);
45.
46. s.d 10.4;
47. }
48.}