java课件代码

上传人:第*** 文档编号:34245058 上传时间:2018-02-22 格式:DOC 页数:18 大小:112KB
返回 下载 相关 举报
java课件代码_第1页
第1页 / 共18页
java课件代码_第2页
第2页 / 共18页
java课件代码_第3页
第3页 / 共18页
java课件代码_第4页
第4页 / 共18页
java课件代码_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《java课件代码》由会员分享,可在线阅读,更多相关《java课件代码(18页珍藏版)》请在金锄头文库上搜索。

1、第一章package cn.edu.zhjnc;class A1public double circleArea(double r)return Math.PI*r*r;class B1double r1,r2,r3;A1 a=new A1();B1(double r1,double r2,double r3)this.r1=r1;this.r2=r2;this.r3=r3;public class AInB public static void main(String args) B1 b=new B1(1,10, 100);System.out.println(b.a.circleArea

2、(b.r1);System.out.println(b.a.circleArea(b.r2);System.out.println(b.a.circleArea(b.r3);2、package cn.edu.zhjnc;class A2A2(int m)System.out.println(A2(+m+);public class ConstructorInherit extends A2 ConstructorInherit(int m)super(m);public static void main(String args) /new ConstructorInherit(100);/A2

3、 a2=new A2(50);/ConstructorInherit constructorInherit=new ConstructorInherit(10);/constructorInherit.A2(100);3、package cn.edu.zhjnc;final class FinalClass FinalClass()System.out.println(It is a final class.);/class FC extends FinalClass/4、package cn.edu.zhjnc;class Apublic double circleArea(double r

4、)return Math.PI*r*r;class Bdouble r1,r2,r3;B(double r1,double r2,double r3)this.r1=r1; this.r2=r2; this.r3=r3;public class ObjectCombine public static void main(String args) B b= new B(1, 10.0, 100.0);A a=new A();System.out.println(a.circleArea(b.r1);System.out.println(a.circleArea(b.r2);System.out.

5、println(a.circleArea(b.r3);5、package cn.edu.zhjnc;public class Person int salary;void employed()if(salary=0) System.out.println(no job);else System.out.println(job);class Children extends Personint age;void printAge()System.out.println(Age:+age);public static void main(String args) Children children

6、=new Children();children.salary=560;children.age=12;children.printAge();children.employed();6、package cn.edu.zhjnc;class A4final int id;A4(int a)id=a;void f()System.out.println(superClass);class B4 extends A4int id;B4(int a)super(a);void f()System.out.println(subClass);void test()System.out.println(

7、id+t+super.id);f();super.f();public static void main(String args) final B4 b4=new B4(5);b4.test();B4 bb=new B4(10);bb.test();/b4=bb;/(new B4(50).test();第二章1、package cn.edu.zhjnc;interface AAvoid minus(int x,int y);int a=100;int b=300;interface BB extends AAvoid time(int x,int y);public class Interfa

8、ceInherit implements AA,BBpublic void minus(int x, int y) System.out.println(x-y);public void time(int x,int y)System.out.println(x*y);public static void main(String args) AA aa=new InterfaceInherit();aa.minus(a, b);BB bb=new InterfaceInherit();bb.time(a,b);/ InterfaceInherit aa=new InterfaceInherit

9、();/ aa.minus(a, b);/ aa.time(a, b);2、package cn.edu.zhjnc;interface Peoplevoid peopleList();class Student implements Peoplepublic void peopleList()System.out.println(I am a student.);class Teacher implements Peoplepublic void peopleList()System.out.println(I am a teacher.);public class InterfaceToU

10、p public static void main(String args) People people;people=new Student();people.peopleList();people=new Teacher();people.peopleList();3、package cn.edu.zhjnc;interface IntA void IntAFun();interface IntB void IntBFun();public class MultiInherit implements IntA,IntBpublic void IntAFun()System.out.prin

11、tln(IntAFun();public void IntBFun()System.out.println(IntBFun();class MultiInheritTestpublic static void main(String args) IntA a;a=new MultiInherit();a.IntAFun();IntB b;b=new MultiInherit();b.IntBFun();/ MultiInherit m=new MultiInherit();/ m.IntAFun();/ m.IntBFun();4、package cn.edu.zhjnc;public int

12、erface MyInterface public abstract void add(int x,int y);public static final int Count=10;/ void add(int x,int y);/ int Count=10;class TestInterface implements MyInterfacepublic void add(int x,int y)System.out.println(x+y);void getA()System.out.println(Count);public static void main(String args) Tes

13、tInterface testInterface=new TestInterface();testInterface.add(10, 20);testInterface.getA();5、package cn.edu.zhjnc;/import java.util.Scanner;abstract class Shapeabstract double getL();abstract double getS();void printSL()System.out.println(L=+this.getL()+,S=+this.getS();class Circle extends Shapedou

14、ble r;Circle(double r)this.r=r;double getL()return 2*Math.PI*r;double getS()return Math.PI*r*r;class Square extends Shapedouble w,h;Square(double w,double h)this.w=w;this.h=h;double getL()return 2*(w+h);double getS()return w*h;class Triangle extends Shapedouble a,b,c;Triangle(double a,double b,doubl

15、e c)this.a=a;this.b=b;this.c=c;double getL()return (a+b+c);double getS()double p=(a+b+c)/2.0;return Math.sqrt(p-a)*(p-b)*(p-c)*p);public class TestAbstract public static void main(String args) Shape s;/ double a,b,c;/ Scanner sc=new Scanner(System.in);/ a=sc.nextDouble();/ b=sc.nextDouble();/ c=sc.nextDouble();/ while(!(a+bc&a-bc)/ a=sc.nextDouble();/ b=sc.nextDouble();/ c=sc.nextDouble();/ / sc.close();/ s=new Triangle(a, b, c);s=new Triangle(3, 4, 5);/向上转型s.printSL();s=new Square(4, 5);s.printSL();s=new Circle(10);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号