nullexceptiondemo.java

来自「了解Java语言的发展历史和Java平台的应用划分。 了解Java语言的特点及」· Java 代码 · 共 23 行

JAVA
23
字号
class Car
{
  void startengine(){};
}
public class NullExceptionDemo{
  Car mycar;
  void start() throws InstantNotInitException{
   if (mycar==null) throw new InstantNotInitException("mycar is null");
   mycar.startengine();}
public static void main(String args[]){
   NullExceptionDemo demo=new NullExceptionDemo();
 try{
       demo.start();
       System.out.println("start car"); 
       return;
  }catch(InstantNotInitException e){
       System.out.println("Got exception:"+e.getMessage()); }}
}
class InstantNotInitException extends Exception{
   public InstantNotInitException(){}
  public InstantNotInitException(String message) {super(message);}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?