考试首页 | 考试用书 | 培训课程 | 模拟考场 | 考试论坛  
全国  |             |          |          |          |          |         
  当前位置:计算机等级 > 二级考试 > Java语言程序设计 > 模拟试题 > 文章内容
  

全国计算机等级考试二级Java模拟试题及答案(28)

中华IT学院   【 】  [ 2016年11月22日 ]
1、编写一个Java程序在屏幕上输出“Hello!”。
public class test
{
public static void main(String[] args)
{
System.out.println("Hello!");
}
}
2、编写一个Java程序在屏幕上输出“Hello, world!”。
public class test
{
public static void main(String[] args)
{
System.out.println("Hello,world");
}
}
3、编写一个Java程序在屏幕上输出“This is java!”。
public class test
{
public static void main(String[] args)
{
System.out.println("This is java!");
}
}
4、编写一个Java程序在屏幕上输出“This is my program!”
public class test
{
public static void main(String[] args)
{
System.out.println("This is my program!");
}
}
5、编写一个Java程序在屏幕上输出“How are you?”
public class test
{
public static void main(String[] args)
{
System.out.println("How are you?");
}
}
6、编写一个圆类Circle,该类拥有:
①一个成员变量
Radius(私有,浮点型);? // 存放圆的半径;
②两个构造方法
Circle( )???????????????? // 将半径设为0
Circle(double? r )???????? //创建Circle对象时将半径初始化为r
class Circle{
private double Radius;
Circle(){
Radius=0.0;}
public Circle(double r){
this. Radius= r;}
}
7、定义一个表示学生信息的类Student,要求如下:
 (1)类Student的成员变量:
sNO 表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。
(2)类Student的方法成员:
getNo():获得学号;
getName():获得姓名;
class Student{
private String sNO;
private String sName;
private char sSex;
private int sAge;
private int sJava;
public Student(String sNo, String sName){
this.sNo = sNo;
this.sName = sName;? }
public String getsNo() {
return sNo; }
public String getsName() {
return sName; }
}
8、定义一个表示水果的类Fruit,要求如下:
(1)类的成员变量: fName表示水果名称,fColor表示水果颜色。
(2)类的成员方法:getName( ):获得水果名称。
class Fruit{
private String fName;
private String fColor;
public Fruit(String fName, String Fcolor ){
this.sName = sName;
this.fColor = fColor;? }
public String getfName() {
return fName; }
}
9、先定义一个类A(该类有成员变量x和y),再定义类A的子类B(要求B新增成员变量z)。
class A{
private int x;
private int y;
public A(int x,int y ){
this.x = x;
this.y = y;? }
}
class B extendsA{
private int z;
public B(int z){
this.z=z;}
}
10、先定义一个类A(该类有成员变量x,成员方法f1( )对x赋初值),再定义类A的子类B(要求B新增成员变量y,新增成员方法f2(? )对y赋初值)。
class A{
private int x;
public A(int x, ){
this.x = x;? }
public int f1x() {
return x; }
}
class B extendsA{
private int y;
public B(int z){
this.y = y;? }
public int f2y() {
return y; }
}
分享到:
本文纠错】【告诉好友】【打印此文】【返回顶部
将考试网添加到收藏夹 | 每次上网自动访问考试网 | 复制本页地址,传给QQ/MSN上的好友 | 申请链接 | 意见留言 TOP
关于本站  网站声明  广告服务  联系方式  站内导航  考试论坛
Copyright © 2007-2013 中华考试网(Examw.com) All Rights Reserved