华南理工大学java模拟题 5.docx
- 文档编号:5657962
- 上传时间:2022-12-30
- 格式:DOCX
- 页数:20
- 大小:18.21KB
华南理工大学java模拟题 5.docx
《华南理工大学java模拟题 5.docx》由会员分享,可在线阅读,更多相关《华南理工大学java模拟题 5.docx(20页珍藏版)》请在冰豆网上搜索。
华南理工大学java模拟题5
四、程序阅读题
1、阅读以下程序,写出输出结果。
publicclassAbc{
publicstaticvoidmain(Stringargs[]){
Abs=newAb("Hello!
","IloveJAVA.");
System.out.println(s);
}
}
classAb{
Strings1;
Strings2;
Ab(Stringstr1,Stringstr2){
s1=str1;
s2=str2;
}
publicStringtoString(){
returns1+s2+"You?
";
}
}
Hello!
IloveJAVA。
You?
2、阅读以下程序,写出输出结果。
publicclassCompare{
publicstaticvoidmain(String[]args){
Stringstr1="abc";
Stringstr2=newString("abc");
Stringstr3="ab"+"c";
Stringstr4=newString(str2);
Stringstr5=str1;
System.out.println(str1==str2);
System.out.println(str2==str3);
System.out.println(str2==str4);
System.out.println(str5==str1);
}
}
False,false,false,true
3、阅读以下程序,写出输出结果。
publicclassGroupTwo{
privateintcount;
publicclassStudent{
Stringname;
publicStudent(Stringn1){
name=n1;
count++;
}
publicvoidOutput(){
System.out.println(this.name);
}
}
publicvoidoutput(){
Students1=newStudent("Johnson");
s1.Output();
System.out.println("count="+this.count);
}
publicstaticvoidmain(Stringargs[]){
GroupTwog2=newGroupTwo();
g2.output();
}
}
Johnson
Count=1
4、阅读以下程序,写出输出结果。
classsuperClass{
inty;
superClass(){
y=30;
System.out.println("insuperClass:
y="+y);
}
voiddoPrint(){
System.out.println("InsuperClass.doPrint()");
}
}
classsubClassextendssuperClass{
inty;
subClass(){
super();
y=50;
System.out.println("insubClass:
y="+y);
}
voiddoPrint(){
super.doPrint();
System.out.println("insubClass.doPrint()");
System.out.println("super.y="+super.y+"sub.y="+y);
}
}
publicclassinviteSuper{
publicstaticvoidmain(Stringargs[]){
subClasssubSC=newsubClass();
subSC.doPrint();
}
}
insuperClass:
y=30
insubClass:
y=50
InsuperClass.doPrint()
insubClass.doPrint()
super.y=30sub.y=50
5、阅读以下程序,写出输出结果。
publicclassGroupThree{
privatestaticintcount;
privateStringname;
publicclassStudent{
privateintcount;
privateStringname;
publicvoidOutput(intcount){
count++;
this.count++;
GroupThree.count++;
GroupThree.this.count++;
System.out.println(count+""+this.count+""+GroupThree.count+""+GroupThree.this.count++);
}
}
publicStudentaStu()
{
returnnewStudent();
}
publicstaticvoidmain(Stringargs[]){
GroupThreeg3=newGroupThree();
g3.count=10;
GroupThree.Students1=g3.aStu();
GroupThree.Students1.Output(5);
}
}
611212
6、阅读以下程序,写出输出结果。
classMammal{
privateintn=40;
voidcrySpeak(Strings){
System.out.println(s);
}
}
publicclassMonkeyextendsMammal{
voidcomputer(intaa,intbb){
intcc=aa*bb;
System.out.println(cc);
}
voidcrySpeak(Strings){
System.out.println("**"+s+"**");
}
publicstaticvoidmain(Stringargs[]){
Mammalmammal=newMonkey();
mammal.crySpeak("Ilovethisgame");
Monkeymonkey=(Monkey)mammal;
puter(10,10);
}
}
**Ilovethisgame**
100
7、阅读以下程序,写出输出结果。
publicclassFlower{
intpetalCount=0;
Strings="initialvalue";
Flower(intpetals){
petalCount=petals;
print("Constructorw/intargonly,petalCount="+petalCount);
}
Flower(Stringss){
print("Constructorw/Stringargonly,s="+ss);
s=ss;
}
Flower(Strings,intpetals){
this(petals);
this.s=s;//Anotheruseof"this"
print("String&intargs");
}
Flower(){
this("hi",47);
print("defaultconstructor(noargs)");
}
voidprintPetalCount(){
print("petalCount="+petalCount+"s="+s);
}
voidprint(Strings){
System.out.println(s);
}
publicstaticvoidmain(String[]args){
Flowerx=newFlower();
x.printPetalCount();
}
}
Constructorw/intargonly,petalCount=47
String&intargs
defaultconstructor(noargs)
petalCount=47s=hi
8、阅读以下程序,写出输出结果。
classCup{
Cup(intmarker){
System.out.println("Cup("+marker+")");
}
voidf(intmarker){
System.out.println("f("+marker+")");
}
}
classCups{
staticCupcup1;
staticCupcup2;
static{
cup1=newCup
(1);
cup2=newCup
(2);
}
Cups(){
System.out.println("Cups()");
}
}
publicclassExplicitStatic{
publicstaticvoidmain(String[]args){
System.out.println("Insidemain()");
Cups.cup1.f(99);
}
}
Insidemain()
Cup
(1)
Cup
(2)
f(99)
9、阅读以下程序,写出输出结果。
classTree{
intheight;
Tree(){
System.out.println("Plantingaseedling");
height=0;
}
Tree(intinitialHeight){
height=initialHeight;
System.out.println("CreatingnewTreethatis"+
height+"feettall");
}
voidinfo(){
System.out.println("Treeis"+height+"feettall");
}
voidinfo(Strings){
System.out.println(s+":
Treeis"+height+"feettall");
}
}
publicclassOverloading{
publicstaticvoidmain(String[]args){
for(inti=0;i<5;i++){
Treet=newTree(i);
t.info();
t.info("overloadedmethod");
}
//Overloadedconstructor:
newTree();
}
}
CreatingnewTreethatis0feettall
Treeis0feettall
overloadedmethod:
Treeis0feettall
CreatingnewTreethatis1feettall
Treeis1feettall
overloadedmethod:
Treeis1feettall
CreatingnewTreethatis2feettall
Treeis2feettall
overloadedmethod:
Treeis2feettall
CreatingnewTreethatis3feettall
Treeis3feettall
overloadedmethod:
Treeis3feettall
CreatingnewTreethatis4feettall
Treeis4feettall
overloadedmethod:
Treeis4feettall
Plantingaseedling
10、阅读以下程序,写出输出结果。
classA{
doublef(doublex,doubley){
returnx*y;
}
}
classBextendsA{
doublef(doublex,doubley){
returnx+y;
}
}
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Bobj=newB();
System.out.println("Theprogramoutputis"+obj.f(6,7));
}
}
Theprogramoutputis13.0
11、阅读以下程序,写出输出结果。
classLargeCup{
LargeCup(intmarker){
System.out.println("LargeCup("+marker+")");
}
voidf1(intmarker){
System.out.println("f1("+marker+")");
}
}
classShelf{
staticLargeCupcup1=newLargeCup
(1);
Shelf(){
System.out.println("Shelf()");
cup2.f1
(1);
}
voidf2(intmarker){
System.out.println("f2("+marker+")");
}
staticLargeCupcup2=newLargeCup
(2);
}
classCupshelf{
staticLargeCupcup3=newLargeCup(3);
staticLargeCupcup4=newLargeCup(4);
Cupshelf(){
System.out.println("Cupshelf()");
cup4.f1
(2);
}
voidf3(intmarker){
System.out.println("f3("+marker+")");
}
staticLargeCupcup5=newLargeCup(5);
}
publicclassInitialization{
staticShelfshelf=newShelf();
staticCupshelfcupshelf=newCupshelf();
publicstaticvoidmain(String[]args){
System.out.println("CreatingnewCupshelf1()inmain");
newCupshelf();
System.out.println("CreatingnewCupshelf2()inmain");
newCupshelf();
shelf.f2
(1);
cupshelf.f3
(1);
newInitialization();
}
}
LargeCup
(1)
LargeCup
(2)
Shelf()
f1
(1)
LargeCup(3)
LargeCup(4)
LargeCup(5)
Cupshelf()
f1
(2)
CreatingnewCupshelf1()inmain
Cupshelf()
f1
(2)
CreatingnewCupshelf2()inmain
Cupshelf()
f1
(2)
f2
(1)
f3
(1)
12、阅读以下程序,写出输出结果。
classPlate{
Plate(intmarker){
System.out.println("Plate("+marker+")");
}
voidf1(intmarker){
System.out.println("f1("+marker+")");
}
}
classDesk{
staticPlateplate1=newPlate
(1);
Desk(){
System.out.println("Desk()");
plate2.f1
(1);
}
voidf2(intmarker){
System.out.println("f2("+marker+")");
}
staticPlateplate2=newPlate
(2);
}
classBoard{
Plateplate3=newPlate(3);
staticPlateplate4=newPlate(4);
Board(){
System.out.println("Board()");
plate4.f1
(2);
}
voidf3(intmarker){
System.out.println("f3("+marker+")");
}
staticPlateplate5=newPlate(5);
}
publicclassInitialization{
staticDeskdesk=newDesk();
BoardBoard=newBoard();
publicstaticvoidmain(String[]args){
System.out.println("CreatingnewBoard()inmain");
newBoard();
System.out.println("Creating2newBoard()inmain");
newBoard();
desk.f2
(1);
//Board.f3
(1);
}
}
Plate
(1)
Plate
(2)
Desk()
f1
(1)
CreatingnewBoard()inmain
Plate(4)
Plate(5)
Plate(3)
Board()
f1
(2)
Creating2newBoard()inmain
Plate(3)
Board()
f1
(2)
f2
(1)
13、阅读以下程序,写出输出结果。
classSwap{
voidsw1(Personx,Persony){
inta=y.id;
y.id=x.id;
x.id=a;
}
voidsw2(Personx,Persony){
Persone;
e=x;
y=x;
x=e;
}
}
publicclassPerson{
intid=0;
Person(intid){
this.id=id;
}
publicstaticvoidmain(String[]args){
Swapcid=newSwap();
Personp1=newPerson(10);
Personp2=newPerson(11);
Personp3=newPerson(12);
Personp4=newPerson(13);
cid.sw1(p1,p2);
cid.sw2(p3,p4);
System.out.println("p1:
"+p1.id+"p2:
"+p2.id);
System.out.println("p3:
"+p3.id+"p4:
"+p4.id);
}
}
p1:
11p2:
10
p3:
12p4:
13
14、阅读以下程序,写出输出结果。
publicclassFoo{
publicstaticvoidmain(String[]args){
StringBuffera=newStringBuffer(“ThisisinSCUT”);
StringBufferb=newStringBuffer(“Twice”);
operate(a,b);
System.out.printIn(a+“,”+b);
}
staticvoidoperate(StringBufferx,StringBuffery){
x.append(y);
y=x;
}
}
ThisisinSCUTTwice,Twice
15、阅读以下程序,写出输出结果。
importstaticnet.mindview.util.Print.*;
classCandy{
static{print("LoadingCandy");}
}
classGum{
static{print("LoadingGum");}
}
classCookie{
static{print("LoadingCookie");}
}
publicclassSweetShop{
publicstaticvoidmain(String[]args){
print("insidemain");
newCandy();
print("AftercreatingCandy");
try{
Class.forName("Gum");
}catch(ClassNotFoundExceptione){
print("Couldn’tfind
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 华南理工大学java模拟题 华南理工大学 java 模拟