编程题:
Class father{fathe() {}
Class sun extends father
{ son() {…..}
Public static void main()
{ son a=new father();
}
}
此程序是否正确,为什么?
第1题:
有如下程序:
include <iostream>
using namespace std;
class PARENT
{
public:
PARENT() { cout <<"PARENT"; }
};
class SON : public PARENT
{
public:
SON() {cout << "SON"; }
};
int main()
{
SON son;
PARENT *p;
p = &son;
return 0;
}
执行上面程序的输出是______。
第2题:
使下列程序正常运行并且输出“Hello!”,横线处应填写的内容是( )。 class Test { public static void main(string[]args){ Test t=new Test; start; } Public void run{ System.out.println("Hello!¨); )
A.extends Thread
B.extends Float
C.extends Iostream
D.extends Stdio
第3题:
写出程序的输出结果
public abstract class A
{
public A()
{
Console.WriteLine('A');
}
public virtual void Fun()
{
Console.WriteLine("A.Fun()");
}
}
public class B: A
{
public B()
{
Console.WriteLine('B');
}
public new void Fun()
{
Console.WriteLine("B.Fun()");
}
public static void Main()
{
A a = new B();
a.Fun();
}
}
第4题:
阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是
A.implements Thread
B.extends Runnable
C.implements Runnable
D.extends Thread
第5题:
A.编译错误
B.200
C.100200
D.100
第6题:
设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果只有一行。()
此题为判断题(对,错)。
第7题:
此题为判断题(对,错)。
第8题:
class One { public One() { System.out.print(1); } } class Two extends One { public Two() { System.out.print(2); } } class Three extends Two { public Three() { System.out.print(3); } } public class Numbers{ public static void main( String[] argv) { new Three(); } } What is the result when this code is executed?()
第9题:
class Bird { static void talk() { System.out.print("chirp "); } } class Parrot extends Bird { static void talk() { System.out.print("hello "); } public static void main(String [] args) { Bird [] birds = {new Bird(), new Parrot()}; for( Bird b : birds) b.talk(); } } 结果为:()
第10题:
现有: class TestA { public void start() { System.out.println("TestA"); } } public class TestB extends TestA { public void start() { System.out.println("TestB"); } public static void main (string[] args) ( ((TestA)new TestB()).start(); ) } 运行结果是哪项?()
第11题:
Base
BaseBase
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第12题:
x = y;
z = x;
y = (B) x;
z = (C) y;
y = (A) y;
第13题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第14题:
下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }
A.t.start
B.t.class
C.t.thread
D.t.static
第15题:
在下列基类的定义中,有无virtual修饰use成员函数的结果将不同,其原因是______。
当use( )为虚拟函数时的程序执行结果:
sizeof(A)=8
sized(B)=12
sizeof(C)=16
当use( )非虚拟函数时的程序执行结果:
sizeof(A)=4
sized(B)=8
sizeof(C)=12
源程序如下:
include<iostream.h>
class Grandad
{
public:
Grandad( ):money(10){}
int money;
virtual void use( ){}
};
class Father:public Grandad
{
public:
Father( ):money(100){}
int money;
void use( ){}
};
class Son:public Father
{
public:
Son( ):money(300){}
int money;
void use( ){}
};
void main(void)
{
Grandad A;Father B;Son C;
cout<<"sizeof(A)="<<sizeof(A)<<endl;
cout<<"sizeof(B)="<<sizeof(B)<<endl;
cout<<"sizeof(C)="<<sizeof(C)<<endl;
}
第16题:
下列程序的输出结果是
class Father{
int m.n;
Father(int a,int B)
{ m=a;
n=b
}
void show ( ){
System.out.println("m and n:"+m+" "+n);
}
}
class Son extends Father{
int p;
Son (int a,int b,int C)
{ super(a,B) ;
p=c;
}
void show(){supur.show( );
System.out.println("p:"+p);
}
}
class Test {
public static void main (String args[ ])
{ Son s:new Son(6,7,8);
s.show( );
}
}
A.m and n:6 8 p:7
B.m andn:6 7 p:8
C.m and n:7 8 p:6
D.m and n:8 7 p:6
第17题:
下列程序创建了一个线程并运行,请在下划线处填入正确代码。
public class Try extends Thread{
public static void main(String args[]){
Threadt=new Try();
【 】;
}
public void run(){
System.out.println(“Try!”);
}
}
第18题:
设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果的第一行是子类。()
此题为判断题(对,错)。
第19题:
设有程序如下: abstract class absclass { abstract void method1(); } class conclass extends absclass { public void method1() { System.out.println("子类");} } public class mainclass { public static void main(String args[]) { absclass ac1=new absclass(); //语句1 absclass ac2=new conclass(); //语句2 ac2.method1(); //语句3 } } 则main()方法中的第一条语句(即语句1)可以顺利通过编译。()
此题为判断题(对,错)。
第20题:
class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?()
第21题:
Many Scottish names begin with M’,Mc or Mac,which means()
第22题:
class Base { Base() { System.out.print(“Base”); } } public class Alpha extends Base { public static void main( String[] args ) { new Alpha(); new Base(); } } What is the result?()
第23题:
Shape
Circle
ShapeCircle
程序有错误