黑马程序员-----toString

-------android培训java培训、期待与您交流! ----------

class  Demo
{   int sum;
    Demo()
    {
       super();
    }
    public boolean equals(Object obj)
    {
 if(!(obj instanceof Demo))
 return  false;
        Demo  d =  (Demo)obj;
 return  this.sum == d.sum;
    }
}

class ObjectDemo()
{
   public static void main(String args[])
   {
       Demo  d1  =  new Demo(3);
       Demo  d2  = new Demo(5);
       Class  demo  = d1.getClass();
       System.out.println(d1.equals(d2));
       System.out.println(d1.toString());
       System.out.println(demo.getname()+Interger.toHexString(d1.hashCode()));
       System.out.println(demo.getname());
   }
}

 

<=================== 内部类 ===================================>
1.内部类访问规则:
  直接访问外部类的成员,包括私有的
2。外部类访问内部类要建立对象


class  Ourter
{
        int x = 3;

private  class Inner    //内部类
{
    void function()
    {
       System.out.println(Ourter.this.x);    //x = 3
    }
}

 void meths()
 { 
     Inner  i =  new Inner();
     i.function();
    System.out.println();
 }
}

class Demo
{
    public static void main()
    {
       Ourter  out  =  new Ourter();
       out.meths();
       Ourter.Inner  in  =  new Ourter().new Inner();
    }
}


《============================知识点==========》

instanceof,是用于判断一个对象是否属于某个类型
switch()内数据类型为byte short char int
除数不能为0时候所报的错误  ----AritchmeticException  要抛出异常
内存溢出 ---OutofMemoruError
runtimeException();

《====================================异常================》

/*
异常就是程序运行时候出现不正常的情况
Error
Exception

try
{
 需要检查的代码;
}
catch(异常类 变量)
{
 处理异常的代码,(处理方式)
}
finally
{
 一定会执行的语句
}
*/

 


class  Functon
{
   int div(int a ,int b) throws Exception
   {
       return a/b;
   }
}

class Demo throws
{
    public static void main(String args[])
    {
       Function fun = new Function();
       try
       {
          int a = fun.div(4,2);
   System.out.println(a);
       }
      catch(Exception e)
      {
          System.out.println(e.getMessage());  //将错误打印出来
   System.out.println(e.toString());  //将错误的异常信息打印出来
   e.printStackTrace();               //异常名称。异常信息,异常位置
      }
     
    }
}

 

class  Functon
{
   int div(int a ,int b)
   { 
 if(b==0)
    throw new AritchmeticException("除数不能为0")   //属于自定义的信息,有提示作用
       return a/b;
   }
}

class Demo throws
{
    public static void main(String args[])
    {
       Function fun = new Function();
       try
       {
          int a = fun.div(4,2);
   System.out.println(a);
       }
      catch(Exception e)
      {
          System.out.println(e.getMessage());  //将错误打印出来
   System.out.println(e.toString());  //将错误的异常信息打印出来
   e.printStackTrace();               //异常名称。异常信息,异常位置
      }
     
    }
}

 


class Person
{
    public void checkName(String name) throws Exception
    {
        if(name.equals("aa"))
 {
     System.out.println("yes");
 }
 else
      System.out.println("no");
    }
}

class P
{
 public static void main(String args[])
 {
    Person   person  =  new  Person();
    try
    {
   person.checkName(null);
    }
    catch(Exception e)
    {
         e.printStackTrace(); 
    }
  
 }  
}


《=============================================》


class RuntimeDemo
{
   public static void main(String args[])
   {
        //Runtime ru   =  Runtime.getRuntime();
 //ru.exec("winmine.exe");

 Date d =  new Date();
 System.out.println(d);

 //时间可以格式化成我们想要的格式

 SimpleDateFormat sdf  = new SimpleDateFormat("yyyy年mm月dd日");
 String  time   =  sdf.format(d);
 System.out.println(time);


   }
}

 

 

-------android培训java培训、期待与您交流! ----------

详细请查看:http://edu.csdn.net/heima/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值