华南理工大学java模拟题

上传人:d****1 文档编号:122757531 上传时间:2022-07-21 格式:DOCX 页数:14 大小:19.54KB
收藏 版权申诉 举报 下载
华南理工大学java模拟题_第1页
第1页 / 共14页
华南理工大学java模拟题_第2页
第2页 / 共14页
华南理工大学java模拟题_第3页
第3页 / 共14页
资源描述:

《华南理工大学java模拟题》由会员分享,可在线阅读,更多相关《华南理工大学java模拟题(14页珍藏版)》请在装配图网上搜索。

1、四、程序阅读题1、阅读以下程序,写出输出结果。public class Abe public static void main(String args) Ab s = new Ab(Hello!, I love JAVA.); System. out.println(s); class Ab String s1;String s2;Ab(S tring st r1, St ring st r2) s1 = str1;s2 = str2;public St ring toSt ring() return s1 + s2 + You?;Hello! I love JAVA。 You?2、阅读以下程

2、序,写出输出结果。public class Compare public static void main(String args) String str1 = abc;String str2 = new String(abc);String str3 = ab + c;String str4 = new String(str2);String str5 = str1;Sys tem.o ut .pri ntl n(s tr1 = st r2);Sys tem.o ut .pri ntl n(s tr2 = st r3);System. out.println(str2 = str4);Sys

3、 tem.o ut .pri ntl n(s tr5 = st r1); False, false, false, true3、阅读以下程序,写出输出结果。 public class GroupTwo private int count;public class Student String name;public Student(String n1) name = n1;count+;public void Output。 Sys tem.o ut .pri ntln(t his.name); public void output() Student s1 = new Student(“Jo

4、hnson); s1. Output();Sys tem.o ut .pri ntln (cou nt二+ t his.cou nt); public static void main(String args) GroupTwo g2 = new GroupTwoO; g2.o utput();JohnsonCount=l4、阅读以下程序,写出输出结果。 class superClass int y;superclass。y = 30;Sys tem.o ut .pri ntln(in superClass:y二+ y); void doPri nt() Sys tem.o ut .pri n

5、tln(In superClass.doPri nt(); class subClass extends superClass int y;subClass() super(); y = 50;Sys tem.o ut .pri ntln(in subClass:y二+ y);void doPri nt() super.doPri nt();Sys tem.o ut .pri ntln(in subClass.doPri nt();Sys tem.o ut .pri ntln (super.y二+ super.y + sub.y二+ y); public class inviteSuper p

6、ublic static void main(String args) subClass subSC = new subClass(); subSC.doPri nt(); in superClass:y=30in subClass:y=50In superClass.doPrint()in subClass.doPrint() super.y=30 sub.y=505、阅读以下程序,写出输出结果。 public class GroupThree private static int count; private String name;public class Student private

7、 int count;private String name;public void Output(int count) count+;t his.cou nt+;GroupThree.count+;GroupThree .this.count+;Sys tem.o ut .pri ntl n(cou nt + + t his.cou nt + + GroupThree.cou nt + + GroupThree .t his.count+);public Stu den t aStu()return new StudentO;public static void main(String ar

8、gs) GroupThree g3 = new GroupThreeO; g3.count = 10;GroupThree.S tudent s1 = g3.aS tu(); GroupThree.Student s1. Output(5);6 1 12 126、阅读以下程序,写出输出结果。class Mammal private int n = 40;void crySpeak(String s) Sys tem.o ut .pri ntl n(s);public class Monkey extends Mammal void computer(int aa, int bb) int cc

9、 = aa * bb;Sys tem.o ut .pri ntl n(cc);void crySpeak(String s) Sys tem.o ut .pri ntln(* + s + *);public static void main(String args) Mammal mammal = new Monkey(); mammal.crySpeak(I love t his game); Monkey monkey = (Monkey) mammal; p ut er(10, 10);*I love this game*1007、阅读以下程序,写出输出结果。 public class

10、Flower int petalCount 二 0;String s = initial value;Flower(i nt pet als) petalCount 二 petals;print(Construetor w/ int arg only, petalCount二+ petalCount); Flower(S tring ss) pri nt( Cons true tor w/ St ring arg only, s = + ss);s = ss;Flower(String s, int petals) this (petals);this.s = s; / Another use

11、 of thisprint(String & int args);Flower() this (hi, 47);print( default eonstruetor (no args); void pri ntPet alCou nt() pri nt( pe talCou nt 二+ pet alCou nt + s = + s); void print(String s) System. out .println(s); public static void main(String args) Flower x = new Flower();x.pri ntPet alCou nt();C

12、onstructor w/ int arg only, petalCount= 4String & int argsdefault constructor (no args)petalCount = 47 s = hi8、阅读以下程序,写出输出结果。class Cup Cup(int marker) Sys tem.o ut .pri ntln (Cup( + marker + );void f(int marker) Sys tem.o ut .pri ntln(f( + marker + );class Cups static Cup cupl;static Cup cup2;static

13、 cupl = new Cup(l);cup2 = new Cup(2);Cups() Sys tem.o ut .pri ntln (Cups();public class ExplicitStatic public static void main(String args) Sys tem.o ut .pri ntln( Inside main(); Cups.cupl.f(99);Inside main()Cup(1)Cup(2)f(99)9、阅读以下程序,写出输出结果。 class Tree int height;Tree() System.out .println(Planting

14、a seedling); height 二 0;Tree(int initialHeight) height 二 initialHeight;System.out .println (Creating new Tree that is + height + feet tall);void info() System.out .println (Tree is + height + feet tall); void info(String s) System.out .println (s + : Tree is + height + feet tall); public class Overl

15、oading public static void main(String args) for(i nt i 二 0; i 5; i+) Tree t 二 new Tree(i); t.info();t.inf o(overloaded met hod);/ Overloaded construetor:new Tree();Creating new Tree that is 0 feet tallTree is 0 feet talloverloaded method: Tree is 0 feet tallCreating new Tree that is 1 feet tallTree

16、is 1 feet talloverloaded method: Tree is 1 feet tallCreating new Tree that is 2 feet tallTree is 2 feet talloverloaded method: Tree is 2 feet tallCreating new Tree that is 3 feet tallTree is 3 feet talloverloaded method: Tree is 3 feet tallCreating new Tree that is 4 feet tallTree is 4 feet tallover

17、loaded method: Tree is 4 feet tallPlanting a seedling10、阅读以下程序,写出输出结果。class A double f(double x, double y) return x * y;class B extends A double f(double x, double y) return x + y;public class Test public static void main(String args) B obj = new B();Sys tem.o ut .pri ntln (The program output is + o

18、bj.f(6, 7); The program output isl3.011、阅读以下程序,写出输出结果。 class LargeCup LargeCup(int marker) Sys tem.o ut .pri ntln (LargeCup(“ + marker + );void f1(int marker) Sys tem.o ut .pri ntln(f1( + marker + );class Shelf static LargeCup cup1 = new LargeCup(1); Shelf() System. out.println(Shelf(); cup2.f1(1);v

19、oid f2(int marker) Sys tem.o ut .pri ntln( f2( + marker + );static LargeCup cup2 = new LargeCup(2);class Cupshelf static LargeCup cup3 = new LargeCup(3);static LargeCup cup4 = new LargeCup(4); Cupshelf() System. out.println(CupshelfO); cup4.f1(2);void f3(int marker) Sys tem.o ut .pri ntln( f3( + mar

20、ker + );static LargeCup cup5 = new LargeCup(5);public class Initialization static Shelf shelf = new Shelf();static Cupshelf cupshelf = new Cupshelf(); public static void main(String args) Sys tem.o ut .pri ntln (Crea ting new Cupshelf1() in main); new Cupshelf();Sys tem.o ut .pri ntln (Crea ting new

21、 Cupshelf2() in main); new Cupshelf();shelf. f2(1); cupshelf f3(1);new Initi aliza tion();LargeCup(1)LargeCup(2)Shelf()f1(1)LargeCup(3)LargeCup(4)LargeCup(5)Cupshelf()f1(2)Creating new Cupshelf1() in mainCupshelf()f1(2)Creating new Cupshelf2() in mainCupshelf()f1(2)f2(1)f3(1)12、阅读以下程序,写出输出结果。 class

22、Plate Plate(int marker) Sys tem.o ut .pri ntln (Pla te(“ + marker + );void f1(int marker) Sys tem.o ut .pri ntln(f1( + marker + );class Desk static Plate plate1 = new Plate(1);Desk() System. out.println(Desk();plate2. f1(1);void f2(int marker) Sys tem.o ut .pri ntln( f2( + marker + );static Plate pl

23、ate2 = new Plate(2);class Board Plate plate3 = new Plate(3); static Plate plate4 = new Plate(4);Board() System. out.println(BoardO); plate4. f1(2);void f3(int marker) Sys tem.o ut .pri ntln( f3( + marker + );static Plate plate5 = new Plate(5);public class Initialization static Desk desk = new Desk()

24、; Board Board = new Board();public static void main(String args) Sys tem.o ut .pri ntln (Crea ting new Board() in main); new Board();Sys tem.o ut .pri ntln (Crea ti ng2 new Board() in main); new Board();desk.f2(1); / Board. f3(1); Plate(1)Plate(2)Desk()f1(1)Creating new Board() in mainPlate(4)Plate(

25、5)Plate(3) Board() f1(2)111Creating2 new Board() in mainPlate(3) Board()1f1(2)f2(1)13、阅读以下程序,写出输出结果。 class Swap void sw1 (Person x, Person y)int a = y.id;y.id = x.id;x.id = a;void sw2 (Person x, Person y)Person e;e = x;y = x;x = e;public class Person int id = 0;Person (int id) t his.id = id;public s

26、tatic void main(String args) Swap cid = new Swap ();Person pl = new Person (10);Person p2 = new Person (11);Person p3 = new Person (12);Person p4 = new Person (13);cid.sw1(p1,p2);cid.sw2(p3,p4);System.out. println(p1: + p1.id + p2: + p2.id); Sys tem.o ut. println(p3: + p3.id + p4: + p4.id);pl: 11p2:

27、 10p3: 12p4: 1314、阅读以下程序,写出输出结果。public class Foo public static void main (String args) St ringBuffer a = new St ringBuffer (“This is in SCUT); StringBuffer b = new StringBuffer (“Twice); opera te(a,b);Sys tem.o ut .pri ntl n(a + ,” +b);static void operate (StringBuffer x, StringBuffer y) x.append(y)

28、;y = x;This is in SCUTTwice,Twice15、阅读以下程序,写出输出结果。impor t static net .mindview, uti l.Pri nt.*;class Candy static print(Loading Candy); class Gum static print(Loading Gum); class Cookie static print(Loading Cookie); public class SweetShop public static void main(String args) print(“inside main);new

29、Candy();print(After creating Candy);try Class.forName(Gum); catch(ClassNotFoundException e) print( Couldnt find Gum);pri nt(After Class.forName(Gum);new Cookie();print(After creating Cookie);inside mainLoading CandyAfter creating CandyLoading GumAfter Class.forName(Gum)Loading CookieAfter creating C

30、ookie16、阅读以下程序,写出输出结果。 public class Class3 public static void main(String args) SubSubClass x = new SubSubClass(10, 20, 30); x.show();class SuperClass int a, b;SuperClass(i nt aa, int bb) a = aa;b = bb;void show() System.out. println(a二+ a + nb= + b); class SubClass extends SuperClass int c;SubClass

31、(i nt aa, int bb, int cc) super(aa, bb);c = cc;class SubSubClass extends SubClass int a;SubSubClass(int aa, int bb, int cc) super(aa, bb, cc);a = aa + bb + cc;void show() nc= + c);System.out. println(a二+ a + nb= + b + a=60b=20c=3017、阅读以下程序,写出输出结果。 class SmallPlate SmallPlate(int i) Sys tem.o ut .pri

32、 ntln (Pla te cons true to r);class DinnerPlate extends SmallPlate DinnerPlate(int i) super(i);System.out .println(DinnerPlate eonstruetor) class Utensil Utensil( int i) Sys tem.o ut .pri ntln(Ut ensil cons true to r);class Spoon extends Utensil Spoon (int i) super(i);Sys tem.o ut .pri ntln (Spoon c

33、ons true to r);class Fork extends Utensil Fork(i nt i) super(i);Sys tem.o ut .pri ntln( Fork cons true to r); class Knife extends Utensil Knife(i nt i) super(i);Sys tem.o ut .pri ntln (Knife cons true to r);/ A eultural way of doing something: class Custom Cus to m(i nt i) Sys tem.o ut .pri ntln (Cu

34、s tom cons true to r);public class PlaceSetting extends Custom private Spoon sp;private Fork frk;private Knife kn;private DinnerPlate pl; public PlaceSetting(int i) super(i + 1);sp = new Spoon(i + 2);frk = new Fork(i + 3);kn = new Knife(i + 4);pl = new DinnerPlate(i + 5);System.out .println(PlaceSet

35、ting construetor); public static void main(String args) PlaceSetting x = new PlaceSetting(9); -Custom constructorUtensil constructorSpoon constructorUtensil constructorFork constructorUtensil constructorKnife constructorPlate constructorDinnerPlate constructorPlaceSetting constructor18、阅读以下程序,写出输出结果

36、。 public class Unchecked public static void main(String args) try met hod(); catch (Exception e) Sys tem. out .pri ntln (A); finally System. out.println(B);static void method() try wrench();System. out.println(C); catch (ArithmeticException e) System. out.println(D); finally System. out.println(E);System. out.println(F);static void wrench() throw new NullPointerException();EA

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!