几道笔试题
来源:互联网 发布:bu大都会学院知乎 编辑:程序博客网 时间:2024/05/01 19:25
1.单例模式
饿汉模式:
特点:加载类慢,获取对象速度快
public class Singleton{ //1.创建私有构造方法 private Singleton(){ }<span></span>private static Singleton instance=new Singleton();//2.创建类的唯一实例<span></span>//3.提供一个用于获取实例的方法 public static Singleton getInstance(){ return instance; }}懒汉模式:
特点:加载类快,获取对象慢
public class Singleton{ //1.创建私有构造方法 private Singleton(){ }private static Singleton instance;//2.声明类的唯一实例//3.提供一个用于获取实例的方法 public static Singleton getInstance(){if(instance==null){instance=new Singleton();} return instance; }}
2.下面代码输出结果为
public class Test1 { public static void changeStr(String str) { str += "welcome"; } public static void main(String[] args) { String str = "1234"; changeStr(str); System.out.println(str); } }
答案为:1234
System.out.println(str); //输出的只是main 方法中的str
3.下面运行结果为
class HelloA { public HelloA() { System.out.println("HelloA"); } { System.out.println("I'm A class"); } static { System.out.println("static A"); }}public class HelloB extends HelloA { public HelloB() { System.out.println("HelloB"); } { System.out.println("I'm B class"); } static { System.out.println("static B"); } public static void main(String[] args) { new HelloB(); }}
输出:
static A
static B
Hello A
I'm A class
Hello B
I'm B class
先执行静态语句 在自上而下
4.判断一个对象是否是一个已知类的对象,关键字 instanceof
例
t = 3;
System.out.println(t instanceof Integer);
0 0
- 几道笔试题
- 几道笔试题
- 几道笔试题
- 几道笔试题
- 几道笔试题
- 几道笔试题
- 几道笔试题
- 几道百度笔试题
- 几道Java笔试题
- 几道js笔试题
- 几道C笔试题
- python几道笔试题
- 几道python笔试题
- 几道php笔试题
- 几道C笔试题
- MSN CDC的几道笔试题
- 几道入门PHP笔试题
- 几道入门PHP笔试题
- python 入门
- 第5章(5) 枚举类型
- ubuntu14.04 配置redmine3.1
- 极光推送详细讲解+错误知识点
- RecyclerView的使用记录
- 几道笔试题
- 统计数字
- [LeetCode265]Paint House II
- display:inline、block、inline-block的区别
- Remove Invalid Parentheses
- [LeetCode266]Palindrome Permutation
- [LeetCode267]Palindrome Permutation II
- 手机原型设计
- MMU段式映射(VA -> PA)过程分析