视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
东软java笔试题附答案
2025-09-24 06:34:37 责编:小OO
文档
1、public static const int num = 9;  判断题

const 成员变量是静态的不需要加static修饰 

2、C#中接口和类的主要区别   问答

接口只包含方法或属性的声明,不包含具体实现方法的代码,接口可以实现多继承(可以实现多个接口),而类只能是单继承,继承(实现)接口的类必须实现接口中声明的方法或属性

3、用sealed修饰的类有什么特点  问答

不可被继承

4、找错误  

   指出下面程序的错误

public class MyTest

    {

        public void Test(ref int i)

        {

            i = 1;

}

public void Test(int i)

        {

            i = 1;

}

public void Test(out int i)

        {

            i = 1;

}

}

Out 和 ref 不能用来重载方法

compiler error CS0663: "cannot define overloaded methods that differ only on ref and out"

5、什么类型的变量可以用foreach 来遍历?问答

    In C#, it is not strictly necessary for a collection class to inherit from IEnumerable and IEnumerator in order to be compatible with foreach; as long as the class has the required GetEnumerator, MoveNext, Reset, and Current members, it will work with foreach. Omitting the interfaces has the advantage of allowing you to define the return type of Current to be more specific than object, thereby providing type-safety.

6、读程序写出输出结果 读程序

    public class MyTest

    {

        static void Main(string[] args)

        {

            MyTest mt = new MyTest();

            mt.Test();

        }

        public void Test()

        {

            StructPoint sp = new StructPoint();

            sp.x = 9;

            sp.y = 10;

            StructPoint retSp = RefreshStructPoint(sp);

            OutputStructPointResult(ref retSp);

            OutputStructPointResult(ref sp);

            retSp = RefreshStructPoint(ref sp);

            OutputStructPointResult(ref retSp);

            OutputStructPointResult(ref sp);

            ClassPoint cp = new ClassPoint(10, 12);

            ClassPoint retCp = RefreshClassPoint(cp);

            OutputClassPointResult(ref retCp);

            OutputClassPointResult(ref cp);

        }

        public void OutputStructPointResult(ref StructPoint sp)

        {

            Console.WriteLine(sp.x);

            Console.WriteLine(sp.y);

        }

        public void OutputClassPointResult(ref ClassPoint cp)

        {

            Console.WriteLine(cp.X);

            Console.WriteLine(cp.Y);

        }

        private StructPoint RefreshStructPoint(ref StructPoint point)

        {

            point.x++;

            point.y++;

            return point;

        }

        private StructPoint RefreshStructPoint(StructPoint point)

        {

            point.x++;

            point.y++;

            return point;

        }

        private ClassPoint RefreshClassPoint(ClassPoint point)

        {

            point.X = 0;

            point.Y = 0;

            return point;

        }

    }

    public struct StructPoint

    {

        public int x;

        public int y;

    }

    public class ClassPoint

    {

        private int x = 0;

        private int y = 0;

        public ClassPoint(int x, int y)

        {

            this.x = x;

            this.y = y;

        }

        public int X

        {

            get

            {

                return x;

            }

            set

            {

                x = value;

            }

        }

        public int Y

        {

            get

            {

                return y;

            }

            set

            {

                y = value;

            }

        }

}

输出结果

10

11

9

10

10

11

10

11

0

0

0

0

7、string 是值类型还是引用类型?下面的代码Main方法中在调用第一个Method 和第二个Method方法后str变量结果分别是什么,是否会被改变

class RefExample

{

    static void Method(ref string s)

    {

        s = "changedRef";

}

static void Method(string s)

    {

        s = "changed";

}

    static void Main()

    {

        string str = "original";

        Method(str);

        Method(ref str);        

    }

}

第一个方法后str = “original”  第二个方法后str = “changedRef”

8、out和ref关键字的作用,有什么不同?

    表示参数是传递引用,out传递前不需要初始化,执行的函数返回前必须赋值,ref传递前必须初始化下载本文

显示全文
专题