单选题:方法testperson()在执行时会出现什么情况?
方法testperson()在执行时会出现什么情况? @[B](1)
已知类:
```
class Person{
String name;
int age;
public void tell(){
System.out.println("我是"+name+",年龄"+age);
}
}
public void testperson() {
Person per=null;
per.name="张三";
per.age=30;
per.tell();
}
```
A. 编译不能通过,有语法错误
B. 程序运行时出现异常 Exception in thread "main" java.lang.NullPointerException
C. 正常执行,执行结果是:
D. 我是“张三”,年龄30
A.编译不能通过,有语法错误
B.程序运行时出现异常 Exception in thread "main" java.lang.NullPointerException
C.正常执行,执行结果是:
D.我是“张三”,年龄30
答案:B
已知类:
```
class Person{
String name;
int age;
public void tell(){
System.out.println("我是"+name+",年龄"+age);
}
}
public void testperson() {
Person per=null;
per.name="张三";
per.age=30;
per.tell();
}
```
A. 编译不能通过,有语法错误
B. 程序运行时出现异常 Exception in thread "main" java.lang.NullPointerException
C. 正常执行,执行结果是:
D. 我是“张三”,年龄30
A.编译不能通过,有语法错误
B.程序运行时出现异常 Exception in thread "main" java.lang.NullPointerException
C.正常执行,执行结果是:
D.我是“张三”,年龄30
答案:B