面试中遇到的题目
1、成员变量和局部变量的区别?
2、Spring的Bean生命周期图?
2、为其画运行内存图:
class Book{ String name; double price; public Book(String name,double price){ this.name = name; this.price = price; } public void getInfo(){ System.out.println("图书名称:"+ name + ",价格:" + price); } public void setPrice(double price){ this.price = price; } } public class Main{ public static void main(String[] args){ Book book = new Book("Java开发指南",66.6); book.getInfo(); //图书名称:Java开发指南,价格:66.6 fun(book); book.getInfo(); //图书名称:Java开发指南,价格:99.9 } public static void fun(Book temp){ temp.setPrice(99.9); } }
调用时为temp在栈中开辟新空间,并指向book的具体内容,方法执行完毕后temp在栈中的内存被释放掉
文章引用: