在保存此类代码时谨记要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);
B());
}
}
------------------------------------------------
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");
return a/b;
/
*}
catch(ArithmeticException e)
{
e.printStackTrace();
throw new Exception("can't divide by zero");
//throw e;
//return 0;
}*/
}
public int fn1(int a,int b) throws ArithmeticException,DivisorIsMinusException//Exception
{
return division(a,b);
}
}
class ChildExcep extends Excep
{
ChildExcep() throws FileNotFoundException
{
}
public int division(int a,int b) throws ArithmeticException,DivisorIsMinusException
{
return a/b;
}
}
class DivisorIsMinusException extends Exception
{
DivisorIsMinusException(String str)
{
super(str);
}
}
class ExcepTest
{
public static int method1(Excep excep)
{
try
{
return excep.division(5,0);
}
catch(ArithmeticException e)
{
System.out.String());
}
catch(DivisorIsMinusException ex)
{
System.out.String());
//it(-1);
//return;
}
return 0;
}
public static void main(String[] args) //throws Exception
{
ChildExcep ce=new ChildExcep();
method1(ce);
Excep excep=new Excep();
try
{
//excep.division(5,0);
excep.fn1(5,-1);
System.out.println("exception");
return;
}
catch(ArithmeticException e)
{
System.out.String());
}
catch(DivisorIsMinusException ex)
{
System.out.String());
//return;
}
catch(Exception e)
{
//System.out.println("can't divide by zero");
//System.out.Message());
/
/System.out.String());
e.printStackTrace();
}
finally
{
System.out.println("finally");
}
System.out.println("finish");
}
}
-------------------------------------------------
interface Machine
{
void run();
}
class Person
{
void run()
{
System.out.println("run");
}
}
class Robot extends Person
{
private class MachineHeart implements Machine
{
public void run()
{
System.out.println("heart run");
}
}
Machine getMachine()
{
return new MachineHeart();
}
}
class Test
{
public static void main(String[] args)
{
Robot robot=new Robot();
Machine Machine();
m.run();
robot.run();
}
}
------------------------------------------------
class Outer
{
private static int index=100;
void fn(fina
l int a)
{
/*final int b=0;
if(true)
{
class Middle
{
private int index=60;
class Inner
{
private int index=50;
void print()
{
int index=30;
System.out.println(index);
System.out.println(this.index);
System.out.println(Middle.this.index);
System.out.println(Outer.this.index);
//a=5;
//b=6;
System.out.println(a);
System.out.println(b);
}
}
}
}*/
}
class Inner
{
private int index=50;
static void print()
{
int index=30;
System.out.println(index);
//System.out.println(this.index);
//System.out.println(Outer.index);
}
}
void print()
{
/* Inner inner=new Inner();
inner.print();*/
}
/*Inner getInner()
{
return new Inner();
}*/
/*public static void main(String[] args)
{
Outer outer=new Outer();
//outer.print();
Inner inner=new Inner();//Inner();
inner.print();
}*/
}
class Test
{
public static void main(String[] args)
{
Outer outer=new Outer();
//outer.print();
//Outer.Inner Inner();
/*Outer.Inner Inner();
inner.print();*/
//Outer.Inner w Inner();
}
}
------------------------------------------------
public class Welcome
{
public static void main(String[] args)
{
//System.out.print("维新:bole\n");
//System.out.println(" Welcome you!");
/*byte b;
b=3;
b=(byte)(b*3);
System.out.println(b);*/
//short s;
/*int i;
long l;*/
/
*char ch;
ch=97;
System.out.println(ch);*/
/*float f;
f=1.3f;
System.out.println(f);*/
//double d;
/*boolean bool;
bool=true;
System.out.println(bool);*/
/*if(true)
{
}*/
//int num[]=new int[3];
/*int[] num;
num={1,2,3}; //error*/
//int [] num1;
//int []num2;
//num=new int[3];
//int [] num=new int[]{1,2,3}; //ok
//int [] num=new int[3]{1,2,3}; //error;
/*int [] num;
num=new int[3];
num[0]=1;
num[1]=12;
num[2]=32;
System.out.println(num[0]);
System.out.println(num[1]);
System.out.println(num[2]);*/
/*int [][] num;
num=new int[3][4];
num[0][1]=12;
num[2][3]=34;*/
/
*int [][] num;
num=new int[3][];
num[0]=new int[5];
num[1]=new int[3];
num[2]=new int[2];
num[0][4]=45;
num[1][2]=34;
num[2][1]=21;
System.out.println(num[0][4]);
System.out.println(num[1][2]);
System.out.println(num[2][1]);
System.out.println(num[2][2]);*/
//int [][] num=new int[][]{1,2,3,4,5,5}; //error
//int [][] num=new int[][]{{1,2,3},{4,5,5}}; //ok
//int [][] num=new int[2][]{{1,2,3},{4,5,5}}; //error
//int [][] num={{1,2,3},{4,5,6}}; //ok
/*int [][] num={{1,2,3},{4,5},{6}};
System.out.println(num[0][2]);
System.out.println(num[1][1]);
System.out.println(num[2][0]);*/
/*int i=3;
//System.out.println(i++);
System.out.println(++i);
*/
/*int i=3;
//int count=(i++)+(i++)+(i++);
int count=(++i)+(++i)+(++i);
System.out.println(i);
System.out.println(count);*/
if()
{
}
while(true)
{
}
do
{
}while(true);
for(int i=0;i<10;i++)
{
}
}
}
------------------------------------------------
class Dmeng implements VideoCard
{
String name;
public Dmeng()
{
name="Dmeng's videocard";
}
public void setName(String name)
{
this.name=name;
}
public void Display()
{
System.out.println("Dmeng's videocard is working");
}
public String getName()
{
return name;
}
}
------------------------------------------------
class Mainboard
{
String strCPU;
VideoCard vc;
void setCPU(String strCPU)
{
this.strCPU=strCPU;
}
void setVideoCard(VideoCard vc)
{
this.vc=vc;
}
void run()
{
System.out.println(strCPU);
System.out.Name());
vc.Display();
System.out.println("Mainboard is running");
}
java源码阅读工具}
------------------------------------------------
class Garbage
{
int index;
static int count;
Garbage()
{
count++;
System.out.println("object "+count+" construct");
setID(count);
}
void setID(int id)
{
index=id;
}
protected void finalize()
{
System.out.println("object "+index+" is reclaimed");
}
public static void main(String[] args)
{
new Garbage();
new Garbage();
new Garbage();
new Garbage();
<();
}
}
------------------------------------------------
interface Math
{
double PI=3.1415926;
}
class Arithmetic implements Math
{
double roundArea(double radius)
{
return PI*radius*radius;
}
}
class Student
{
public static void main(String[] args)
{
Arithmetic a=new Arithmetic();
System.out.undArea(3));
System.out.println(Math.PI);
System.out.println(Arithmetic.PI);
System.out.println(a.PI);
}
}
------------------------------------------------
interface Sittable
{
void sit();
}
interface Lie
{
void sleep();
}
/*interface Chair extends Sittable
{
}
interface Sofa extends Sittable,Lie
{
}*/
/*class Sofa implements Sittable,Lie
{
public void sit()
{
}
public void sleep()
{
}
}*/
interface HealthCare
{
void massage();
}
class Chair implements Sittable
{
public void sit(){};
}
class Sofa extends Chair implements Lie,HealthCare
{
public void sleep(){};
public void massage(){};
}
------------------------------------------------
bole;
//package com.winsunlight;
bole.Test;
public class Test2 extends Test
{
public void proMethod()
{
}
public void fn()
{
//pubMethod();
//proMethod();
//defMethod();
/
/priMethod();
}
public static void main(String[] args)
{
/*Test t=new Test();
//t.pubMethod();
//t.proMethod();
t.defMethod();
t.priMethod();*/
}
}
-
-----------------------------------------------
class Test
{
public static void main(String[] args)
{
int i=0xffffffff;
//int c=i<<2;
//int c=i>>2;
int c=i>>>2;
System.out.println(i);
System.out.HexString(c));
}
}
------------------------------------------------
class Point
{
int x,y;
static int z;
static final double PI=3.1415926;
Point(int a,int b)
{
// PI=3.1415926;
x=a;
y=b;
}
Point()
{
// PI=3.1415926;
this(1,1);
}
static void output()
{
System.out.println("output() called");
System.out.println(z);
// System.out.println(x);
// System.out.println(y);
}
void output(int x,int y)
{
output();
z=5;
this.x=x;
this.y=y;
}
public static void main(String[] args)
{
Point pt1=new Point();
Point pt2=new Point();
pt1.z=5;
pt2.z=6;
System.out.println(pt1.z);
System.out.println(pt2.z);
//pt.output();
//Point.output();
//Point pt;
/
/pt=new Point(3,3);
//pt=new Point();
//pt.output(5,5);
//pt=new Point();
//pt.x=10;
//pt.y=10;
//pt.output();
/*Point pt2=new Point();
//pt2.output();
pt.x=6;
pt2.x=7;
System.out.println(pt.x);
System.out.println(pt2.x);*/
}
}
------------------------------------------------
class Rectangle
{
int l,w;
int perimeter()
{
return 2*(l+w);
}
int area()
{
return l*w;
}
public static void main(String[] args)
{
Rectangle rect1=new Rectangle();
Rectangle rect2=new Rectangle();
rect1.l=10;
rect1.w=5;
System.out.println("perimeter of rect1 = "+rect1.perimeter());
System.out.println("area of rect1 = "+rect1.area());
rect2.l=6;
rect2.w=4;
System.out.println("perimeter of rect2 = "+rect2.perimeter());
System.out.println("area of rect2 = "+rect2.area());
}
}
------------------------------------------------
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论