在保存此类代码时谨记要java格式的!
------------------------------------------------
class HelloWorld {
public native void displayHelloWorld();
static
{
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}
------------------------------------------------
interface VideoCard
{
void Display();
String getName();
}
------------------------------------------------
interface Sport
{
void run();
void jump();
}
class Athlete implements Sport
{
public void run()
{
System.out.println("短跑");
}
public void jump()
{
System.out.println("三级跳");
}
public static void main(String[] args)
{
Athlete zhangsan=new Athlete();
zhangsan.run();
zhangsan.jump();
}
}
------------------------------------------------
class Computer
{
public static void main(String[] args)
{
Dmeng d=new Dmeng();
Mainboard m=new Mainboard();
m.setCPU("Intel's CPU");
m.setVideoCard(d);
m.run();
}
}
------------------------------------------------
class Car
{
class Wheel
{
}
}
class PlaneWheel extends Car.Wheel
{
PlaneWheel(Car car)
{
car.super();
}
public static void main(String[] args)
{
Car car=new Car();
PlaneWheel pw=new PlaneWheel(car);
}
}
------------------------------------------------
class A
{
void fn1()
{
}
}
abstract class B
{
abstract void fn2();
}
class C extends A
{
B getB()
{
return new B()
{
public void fn2()
{
}
};
}
}
class Test
{
static void method1(A a)
{
a.fn1();
}
static void method2(B b)
{
b.fn2();
}
public static void main(String[] args)
{
C c=new C();
method1(c);
method2(c.getB());
}
}
------------------------------------------------
class Animal
{
int height,weight;
Animal(int height,int weight)
{
// System.out.println("animal construct");
}
void eat()
{
System.out.println("animal eat");
}
void sleep()
{
System.out.println("animal sleep");
}
void breathe()
{
System.out.println("animal breathe");
}
}
class Fish extends Animal
{
int height;
Fish()
{
super(30,40);
//Animal(30,40);
// System.out.println("fish construct");
}
/*void breathe()
{
// super.breathe();
// super.height=40;
System.out.println("fish bubble");
}*/
}
class Integration
{
static void fn(Animal an)
{
an.breathe();
}
public static void main(String[] args)
{
//Animal an=new Animal();
/*Fish fh=new Fish();
Animal an;
an=fh;
Integration.fn(an);*/
//an.breathe();
// fh.height=30;
// fh.breathe();
Animal an=new Animal(30,40);
Fish fh=new Fish();
an=fh;
/*if(an instanceof Animal)
{
System.out.println("an is animal's instance");
}
if(fh instanceof Fish)
{
System.out.println("fh is fish's instance");
}*/
if(an insta
nceof Fish)
{
System.out.println("an is fish's instance");
}
else
{
System.out.println("an isn't fish's instance");
}
if(fh instanceof Animal)
{
System.out.println("fh is animal's instance");
}
else
{
System.out.println("fh isn't animal's instance");
}
}
}
------------------------------------------------
import java.io.*;
class Excep
{
Excep() throws ArithmeticException
{
}
public int division(int a,int b) throws ArithmeticException,DivisorIsMinusException//Exception
{
//try
//{
if(b<0)
throw new DivisorIsMinusException("Divisor can't be minus");