-------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);
}
}
本文介绍了Java和Android开发技能培训的相关内容,包括内部类访问规则、异常处理、自定义异常及运行时错误处理等核心技术,旨在帮助开发者提升技能并解决常见问题。
3302

被折叠的 条评论
为什么被折叠?



