已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第一章package .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(b.r1);System.out.println(b.a.circleArea(b.r2);System.out.println(b.a.circleArea(b.r3);2、package .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 a2=new A2(50);/ConstructorInherit constructorInherit=new ConstructorInherit(10);/constructorInherit.A2(100);3、package .zhjnc;final class FinalClass FinalClass()System.out.println(It is a final class.);/class FC extends FinalClass/4、package .zhjnc;class Apublic double circleArea(double r)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.println(a.circleArea(b.r3);5、package .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=new Children();children.salary=560;children.age=12;children.printAge();children.employed();6、package .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(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 .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 InterfaceInherit 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();/aa.minus(a, b);/aa.time(a, b);2、package .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 InterfaceToUp public static void main(String args) People people;people=new Student();people.peopleList();people=new Teacher();people.peopleList();3、package .zhjnc;interface IntA void IntAFun(); interface IntB void IntBFun(); public class MultiInherit implements IntA,IntBpublic void IntAFun()System.out.println(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 .zhjnc;public interface 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) TestInterface testInterface=new TestInterface();testInterface.add(10, 20);testInterface.getA();5、package .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 Shapedouble 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,double 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);s.printSL();6、package .zhjnc;class A1 A1()System.out.println(A1()t);void f()System.out.println(A1.f()t);class B1 extends A1void f()System.out.println(B1.f()t);void g()System.out.println(B1.g()t);public static void main(String args) A1 a1=new B1();B1 b1=(B1)a1;/只能针对指向子类对象的父类对象引用进行向下转换a1.f();b1.f();b1.g();7、package .zhjnc;class A A()System.out.println(A()t);void f()System.out.println(A.f()t);class B extends Avoid f()System.out.println(B.f()t);void g()System.out.println(B.g()t);public static void main(String args) A a1=new A();A a2=new B();a1.f();a2.f();/a2.g();第三章1、package mylib.simple.test;import mylib.simple.Public;public class TestPublic public static void main(String args) Public public1=new Public();public1.x=10;public1.prn();2、package mylib.simple;public class Base private int x;private void print()System.out.println(x);void doprint()print();3、package mylib.simple;class Defalut protected int x;void prn()System.out.println(x);4、package mylib.simple;public class Private int a=10;private class Innint b=5;public void getA()System.out.println(a);public void getS()getB();public void getB()Inn inn=new Inn();System.out.println(inn.b);public void getN()Inn inn=new Inn();inn.getA();inn.getS();public static void main(String args) Private private1=new Private();private1.getB();private1.getN();5、package mylib.simple;public class Public public int x;public void prn()System.out.println(x);6、package mylib.simple;/import mylib.simple.*;public class TestBase public static void main(String args) /mylib.simple.Base base=new mylib.simple.Base();/Base base=new Base();/base.x=5;/base.print();7、package mylib.simple;class TestDefault public static void main(String args) Defalut defalut=new Defalut();defalut.x=10;defalut.prn();第四章1、package mypro01;public class Hello public static void main(String args)int a=32;int b=a*2;int c=b*5;System.out.println(c);2、package mypro01;/* * (#)Text1.java * * * author * version 1.00 2013/12/16 */public class HelloWorld public static void main (String args) System.out.println(Hello World!); 第五部分1、package myPro02;class CleverCircle1 double r;CleverCircle1(double x)r=x;double getL()return 2*Math.PI*r;double getS()return Math.PI*r*r;2、package myPro02;class CleverCircle double r;CleverCircle(double x)r=x;double getL()return 2*Math.PI*r;double getS()return Math.PI*r*r;class CleverCircleTestpublic static void main(String args) CleverCircle cc=new CleverCircle(2);System.out.println(cc.getL()+t+cc.getS();cc=new CleverCircle(3.5);System.out.println(cc.getL()+t+cc.getS();3、package myPro02;public class Flower static int num=0;Flower()num+;System.out.println(num+朵花开了!);public static void main(String args) new Flower();new Flower();new Flower();4、package myPro02;public class HelloWorld public static void main(String args) System.out.println(Hello World!);5、package myPro02;public class NewFlower static int num=0;public NewFlower() num+;System.out.println(num+朵花开了!);NewFlower(String color)num+;System.out.println(num+朵花开了!.是+color+花);public static void main(String args) new NewFlower();new NewFlower(红);new NewFlower(黄);6、package myPro02;public class Rectangle double w;double h;Rectangle(double x)w=h=x;Rectangle(double x,double y)w=x;h=y;double getS()return w*h;7、package myPro02;public class RectangleTest public static void main(String args) System.out.println(new Rectangle(2.3,4.5).getS();System.out.println(new Rectangle(7.6).getS();8、package myPro02;class Testpublic static void main(String args) CleverCircle cc=new CleverCircle(2);System.out.println(cc.getL()+t+cc.getS();cc=new CleverCircle(3.5);System.out.println(cc.getL()+t+cc.getS();9、package myPro02;public class TestB int a,b,c;TestB(int a,int b,int c)this.a=a;this.b=b;this.c=c;System.out.println(a+b+c);TestB(int a,int b)/第一个构造方法this.a=a;/a+;this.b=b;/b+;System.out.println(a+-+b+t+this.sum();/调用成员方法TestB(int a)this(1, a);/第二个构造方法,调用前一个构造方法TestB()this(1,100,1);int sum()int s=0;for (int i = a; i =b; i+) s+=i;return s;public static void main(String args) new TestB(10,20); new TestB(100);new TestB();10、 package myPro02; public class TestInitA int x;Flower flower;boolean b;public static void main(String args) TestInitA ti=new TestInitA();System.out.println(x is +ti.x);System.out.println(flower is +ti.flower);System.out.println(b is +ti.b);11、package myPro02;public class TestInitB public static void main(String args) int x=100;System.out.println(nx is +x);12、package myPro02;public class TestInitC int x=3;TestInitC()x=5;public static void main(String args) TestInitC t=new TestInitC();System.out.println(t.x);13、package myPro02;public class TestInitD TestInitD()x=5;int x=3;public static void main(String args) TestInitD t=new TestInitD();System.out.println(t.x);14、package myPro02;class BB(int m)System.out.println(B(+m+);class AB b1=new B(1);static B b2=new B(2);public class TestInitE public static void main(String args) System.out.println(Creating an A object.);new A();System.out.println(Creating another A object.);new A();15、package myPro02;public class TestOL int x;void func()System.out.println(no arg);String func(int i)return arg is +i;void func(String s)System.out.println(s);public static void main(String args) TestOL c=new TestOL();c.func();c.func(c.func(100);16、package myPro02;public class TestOL1 void func(double x)System.out.println(x+ is double);void func(int x)System.out.println(x+ is int);public static void main(String args) TestOL1 c=new TestOL1();c.func(1);c.func(2.5);c.func(3.5f);17、package myPro02;public class ThisTest int a;ThisTest(int b)/参数(方法中的变量)与成员变量同名this.a=b; /成员变量a取得参数值 a+;public static void main(String args) System.out.println(new ThisTest(5).a);/结果是5还是6?第六部分1、package .zhjnc.test;import mylib.simple.List;public
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 部队安全教育课件题目
- 针刺配合推拿治疗神经根型颈椎病30例临床疗效观察
- 市妇幼保健院党支委会议决策制度
- 法律知识问答题库答案
- 企业管理-网络信号差的申请报告模板
- 家庭教育亲子互动测试与答案详解
- 法院安全讲座课件
- 教育行业教师招聘考试题库及答案含岗位模型
- 恐惧症识别与应对方法测试题集
- 康复护理实操技能测试题及答案
- 《氯甲烷合成工艺副产稀硫酸》
- 钢结构厂房模块化施工技术与质量控制体系研究
- 公路维修养护质量保证体系
- 国家电投集团五凌电力有限公司笔试
- 【地理】跨学科主题学习 认识我国的“世界灌溉工程遗产”课件-2025-2026学年八年级地理上学期(人教版2024)
- 道路监控维护合同范本
- 70岁以上老人考驾照,三力测试题库(含答案)
- 烟叶知识培训总结课件
- 化工自动化仪表培训课件
- 小学生食品安全知识讲座
- 建筑工程知识产权课件
评论
0/150
提交评论