java程序设计基础题

java程序设计基础题,第1张

选c;

第一个输出的是(5, 3),应该没有问题吧,

第二个输出的是(3, 5) ,是witchCoords()函数里的输出语句,在witchCoords()函数里的x和y实现了交换,所以是3和5;

第三个输出的是(5, 3),因为传递给switchCoords()函数的值是数据值。switchCoords()里x和y的值改变不会影响实参!

也就是说,传数据值形参的改变不会影响实参;而传地址值形参的改变会影响实参。

如果传递的是数组,实参会随着形参而改变。

对几个容易错的稍微注解下,

1 D

2 C final修饰

3 B

4 B

5 C

6 B

7 C

8 C

9 B JAVA里面都是写作null的,而不是NULL

10 A: Stringsubstring()大小写问题

11 C

12C

13A

14C

15A

16B

17C

18C

19D

20D管道流,此流一般用于多线

第一题有问题:1、创建Person接口(即“人”),它有setData()和getData()方法对“人”属性name、sex和birthday赋值和获得这些属性组成的字符串信息。

问题是:你说要创建一个人(接口),然后里面有方法对人的属性进行赋值?这怎么可能呢,接口是没有成员变量(属性)的,怎么能赋值?接口里只能有常量。

第二题可以答一下:

package pillar;

public class Pillar { private Geometry buttom;

private double height;

public Pillar() {

// TODO Auto-generated constructor stub

}

public Pillar(Geometry button,double height){

thisbuttom = button;

thisheight = height;

}

public double getVolume(){

return thisbuttomgetArea()height;

}

public Geometry getButtom() {

return buttom;

}

public void setButtom(Geometry buttom) {

thisbuttom = buttom;

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

thisheight = height;

}

}

------------------------------------------------类分割线---------------------------------------------------------

package pillar;

public interface Geometry { double getArea();

}

------------------------------------------------类分割线---------------------------------------------------------

package pillar;

public class Circle implements Geometry { private double r;

public Circle() {

// TODO Auto-generated constructor stub

}

public Circle(double r) {

thisr = r;

}

public double getArea() { return MathPIrr;

}

public double getR() {

return r;

}

public void setR(double r) {

thisr = r;

}

}

------------------------------------------------类分割线---------------------------------------------------------

package pillar;

public class Rectangle implements Geometry { private double width;

private double height;

public Rectangle() {

// TODO Auto-generated constructor stub

}

public Rectangle(double width, double height) {

thiswidth = width;

thisheight = height;

}

public double getArea() { return thiswidththisheight;

}

public double getWidth() {

return width;

}

public void setWidth(double width) {

thiswidth = width;

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

thisheight = height;

}

}

------------------------------------------------类分割线---------------------------------------------------------

package pillar;

public class TestPillar {

/ @param args

/

public static void main(String[] args) {

Circle c = new Circle(5);

Rectangle r = new Rectangle(3,4);

Pillar p1 = new Pillar(c,6);

Pillar p2 = new Pillar(r,6);

Systemoutprintln("圆的体积:"+p1getVolume()+"\t矩形的体积:"+p2getVolume());

}

}

1Object

2final

3Object

4this,super

一、读程序写结果

1100

 

2

数组a:123456,200,300

数组b:123456,200,300

数组b的长度: 3

 

3

a=10

b=30

c=60

Time类:

package demo;

import javautilCalendar;

public class Time {

private int hour;

private int min;

private int sec;

public int getHour() {

return hour;

}

public void setHour(int hour) {

thishour = hour;

}

public int getMin() {

return min;

}

public void setMin(int min) {

thismin = min;

}

public int getSec() {

return sec;

}

public void setSec(int sec) {

thissec = sec;

}

Time(){

Calendar cal = CalendargetInstance();

thishour = calget(CalendarHOUR);

thismin = calget(CalendarMINUTE);

thissec = calget(CalendarSECOND);

}

Time(long l){

Calendar cal = CalendargetInstance();

calsetTimeInMillis(l);

thishour = calget(CalendarHOUR);

thismin = calget(CalendarMINUTE);

thissec = calget(CalendarSECOND);

}

}

测试类:

package demo;

public class Test {

public static void main(String[] args) {

Time time1 = new Time();

Time time2 = new Time(555550000);

Systemoutprintln(time1getHour()+"小时\t"+time1getMin()+"分钟\t"+time1getSec()+"秒");

Systemoutprintln(time2getHour()+"小时\t"+time2getMin()+"分钟\t"+time2getSec()+"秒");

}

}

shape接口

圆类

矩形类

三角形类1

三角形类2

测试类

并没有全部实现,其实比较简单,主要功能都没有实现,

还是自己慢慢研究研究吧,只写了个框架出来。

import javautilDate;

import javautilScanner;

public class ChinaBank {

private String account;

private String name;

private Date accountDate;

private double desposit;

private double interest;

//构造方法

public ChinaBank(){

}

//构造方法

public ChinaBank(String name,Date accountDate){

thisname = name;

thisaccountDate = accountDate;

}

public String getAccount() {

return account;

}

public Date getAccountDate() {

return accountDate;

}

public double getDesposit() {

return desposit;

}

public double getInterest() {

return interest;

}

public String getName() {

return name;

}

public void setAccount(String account) {

thisaccount = account;

}

public void setAccountDate(Date accountDate) {

thisaccountDate = accountDate;

}

public void setDesposit(double desposit) {

thisdesposit = desposit;

}

public void setInterest(double interest) {

thisinterest = interest;

}

public void setName(String name) {

thisname = name;

}

//查询

public double search(){

// 补充

return 00;

}

//存款

public void desposit(){

//实现

}

//

public static void main(String args){

ChinaBank c = new ChinaBank();

csetAccount("张三");

//设置

Scanner s = new Scanner(Systemin);

int operate = snextInt();

boolean go = true;

while(go){

switch(operate){

case 1:csearch();break;

case 2:cdesposit();break;

//实现

case 4:Systemoutprintln("欢迎使用柜员机系统");go= false;break;

default:Systemoutprintln("输入无效");break;

}

}

}

}

以上就是关于java程序设计基础题全部的内容,包括:java程序设计基础题、《JAVA程序设计》考题急求答案,急求java试题简答,java课后习题答案.(拒绝打酱油)、JAVA语言程序设计两道练习题。谢谢!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9806937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存