阅读下面代码:
import java.awt.*;
public class Exam11_1
{
private Frame. f;
private Button b1,b2,b3,b4;
public static void main(String args[]
{
Exam11_1 that = new Exam11 1 ();
that.go();
}
public void go()
{
______;
f.setLayout(new FlowLayout()) ;;
b1 = new Button ("Button 1");
b2 = new Button ("Button 2");
b3 = new Button ("Button 3");
b4 = new Button ("Button 4");
f.add (b1);
f.add (b2);
f.add (b3);
f.add (b4);
f.pack ();
f.setVisible (true);
}
}
请在程序中画线处填写正确的语句【 】,以便编译运行程序后得到正确的结果。
第1题:
下面这个程序的结果是
#include<iostream.h>
class A
{
private:
int a;
public:
void seta( ) ;int geta( ) ;};
void A: :seta( )
{ a=1;}
int A: :geta( )
{ retum a;}
class B
{ private:
int a;
public:
void seta( ) ;int geta( ) ;};
void B: :seta( )
{a=2;}
int B: :geta( )
{return a;}
class C: public A,public B
{ private:
int b;
public:
void display( ) ;};
void C: :display( )
{ int b=geta( ) ;
cout < < b;}
void main( )
{ C c;
c. seta( ) ;
c. display( ) ;}
A.1
B.2
C.随机输出1或2
D.程序有错
第2题:
阅读下面程序:
include <iostream.h>
template <class T>
class TAdd
{
private:
T x, y;
public:
TAdd(T a, T b)
{
x=a;
y=b;
}
T add()
{
return x +y;
}
};
void main( )
{
TAdd<int>a(5,6);
TAdd<double>b(2.4,5.8);
cout<<"s1 ="<<A. add()<<",";
cout<<"s2="<<B, add()<<end1;
}
写出该程序的运行结果:【 】。
第3题:
判断下面程序编译是否正确,如果错误简要说明原因 class B{ public: B(int a){ x=a; } private: int x; }; class D : public B{ public: D(int a ) : y(a){ } private: int y; };
第4题:
下面程序的结果为 #include<iostream.h> int c; class A { private: int a; static int b; public: A( ) {a=0;c=0;} void seta( ){a++;} void setb( ){b++;}
A.1 2 1
B.1 2 2
C.1 1 2
D.2 2 2
第5题:
访问修饰符作用范围由大到小是( )
A)private-default-protected-public
B)public-default-protected-private
C)private-protected-default-public
D)public-protected-default-private
第6题:
访问修饰符作用范围由大到小是
A.private-default-protected-public
B.public-default-protected-private
C.private-protected-default-public
D.public-protected-default-private