-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcep3.java
More file actions
19 lines (17 loc) · 762 Bytes
/
Copy pathExcep3.java
File metadata and controls
19 lines (17 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class Excep3{
public static void main(String []args)
{
String name=null;
System.out.println("yoo first line");
System.out.println("String length is "+name.length());//no compile time error...exception
System.out.println("yoo..im not printed");
}
}
/*
null means not assigned any string
name is not pointing to any string objrct..it has null
name.length() is wrong..coz name not pointing to any string...length() is illegal.
so when any reference varible not refering to any objct n we try to call the method of that objct
whcich run only when object exist..then in tht situation NullPointerException arises.
java create objct of NullPointerException n throw it..catch by default catch mechanism..msg printed.progm end.
*/