码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • JAVA题库——关于java中的方法


    目录

    一. 单选题

    1. (单选题)You should fill in the blank in the following code with .public class Test {public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5));}public static getGrade(double score) { if (score >= 90.0)return 'A';else if (score >= 80.0) return 'B';else if (score >= 70.0) return 'C';else if (score >= 60.0) return 'D';elsereturn 'F';}}

    2. (单选题)Which of the following is the best for generating random integer 0 or 1?

    3. (单选题)  is a simple but incomplete version of a method.

    4. (单选题)Analyze the following code.public class Test {public static void main(String[] args) { System.out.println(m(2));}public static int m(int num) { return num;}public static void m(int num) { System.out.println(num);}}

    5. (单选题)Arguments to methods always appear within .

    6. (单选题)Given the following methodstatic void nPrint(String message, int n) { while (n > 0) { System.out.print(message);n--;}}What is k after invoking nPrint("A message", k)?int k = 2;nPrint("A message", k);

    7. (单选题)What is k after the following block executes?{int k = 2;nPrint( );}System.out.println(k);

    8. (单选题)Analyze the following code:public class Test {public static void main(String[] args) { System.out.println(xMethod(5, 500L));}public static int xMethod(int n, long l) { System.out.println("int, long");return n;}public static long xMethod(long n, long l) { System.out.println("long, long");return n;}}

    9. (单选题)Suppose your method does not return any value, which of the following keywords can be used as a return type?

    10. (单选题)The signature of a method consists of .

    11. (单选题)  is to implement one method in the structure chart at a time from the top to the bottom.

    12. (单选题)You should fill in the blank in the following code with .public class Test {public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5);System.out.print("The grade is "); printGrade(59.5);}public static printGrade(double score) { if (score >= 90.0) {System.out.println('A');}else if (score >= 80.0) { System.out.println('B');}else if (score >= 70.0) { System.out.println('C');}else if (score >= 60.0) { System.out.println('D');}else { System.out.println('F');}}}

    14. (单选题)All Java applications must have a method .

    15. (单选题)Analyze the following code.public class Test {public static void main(String[] args) { System.out.println(max(1, 2));}public static double max(int num1, double num2) { System.out.println("max(int, double) is invoked");if (num1 > num2) return num1;elsereturn num2;}public static double max(double num1, int num2) { System.out.println("max(double, int) is invoked");if (num1 > num2) return num1;elsereturn num2;}}

    16. (单选题)Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as , which stores elements in last-in first-out fashion.

    17. (单选题)Analyze the following code:class Test {public static void main(String[] args) { System.out.println(xmethod(5));}public static int xmethod(int n, long t) { System.out.println("int");return n;}public static long xmethod(long n) { System.out.println("long");return n;}}

    18. (单选题)A variable defined inside a method is referred to as .

    19. (单选题)(char)('a' + Math.random() * ('z' - 'a' + 1)) returns a random character 

    20. (单选题)Given the following method, what is the output of the call nPrint('a', 4)?static void nPrint(String message, int n) { while (n > 0) { System.out.print(message);n--;}}

    21. (单选题)Which of the following should be defined as a void method?

    22. (单选题)(int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number .

    23. (单选题)Does the method call in the following method cause compile errors?public static void main(String[] args) { Math.pow(2, 4);}

    24. (单选题)(int)(Math.random() * (65535 + 1)) returns a random number .

    25. (单选题)Does the return statement in the following method cause compile errors?public static void main(String[] args) { int max = 0;if (max != 0) System.out.println(max); elsereturn;}

    二. 多选题

    26. (多选题)The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as .

    一. 单选题

    1. (单选题)You should fill in the blank in the following code with .
    public class Test {
    public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5));
    }
    public static getGrade(double score) { if (score >= 90.0)
    return 'A';
    else if (score >= 80.0) return 'B';
    else if (score >= 70.0) return 'C';
    else if (score >= 60.0) return 'D';
    else
    return 'F';
    }
    }

    • A. int
    • B. double
    • C. boolean
    • D. char
    • E. void

    我的答案: D

    2. (单选题)Which of the following is the best for generating random integer 0 or 1?

    • A. (int)Math.random()
    • B. (int)Math.random() + 1
    • C. (int)(Math.random() + 0.5)
    • D. (int)(Math.random() + 0.2)
    • E. (int)(Math.random() + 0.8)

    我的答案: C

    3. (单选题)  is a simple but incomplete version of a method.

    • A. A stub
    • B. A main method
    • C. A non-main method
    • D. A method developed using top-down approach

    我的答案: A

    4. (单选题)Analyze the following code.
    public class Test {
    public static void main(String[] args) { System.out.println(m(2));
    }

    public static int m(int num) { return num;
    }

    public static void m(int num) { System.out.println(num);
    }
    }

    • A. The program has a compile error because the two methods m have the same signature.
    • B. The program has a compile error because the second m method is defined, but not invoked in the main method.
    • C. The program runs and prints 2 once.
    • D. The program runs and prints 2 twice.

    我的答案: A

    5. (单选题)Arguments to methods always appear within .

    • A. brackets
    • B. parentheses
    • C. curly braces
    • D. quotation marks

    我的答案: B

    6. (单选题)Given the following method
    static void nPrint(String message, int n) { while (n > 0) { System.out.print(message);
    n--;
    }
    }

    What is k after invoking nPrint("A message", k)?

    int k = 2;
    nPrint("A message", k);

    • A. 0
    • B. 1
    • C. 2
    • D. 3

    我的答案: C

    7. (单选题)What is k after the following block executes?
    {
    int k = 2;
    nPrint( );
    }
    System.out.println(k);

    • A. 0
    • B. 1
    • C. 2
    • D. k is not defined outside the block. So, the program has a compile error 答案:d k is defined inside the block. Outside the block, k is not defined.

      #
      Section 6.10 Case Study: Generating Random Characters

    我的答案: A

    8. (单选题)Analyze the following code:
    public class Test {
    public static void main(String[] args) { System.out.println(xMethod(5, 500L));
    }

    public static int xMethod(int n, long l) { System.out.println("int, long");
    return n;
    }

    public static long xMethod(long n, long l) { System.out.println("long, long");
    return n;
    }
    }

    • A. The program displays int, long followed by 5.
    • B. The program displays long, long followed by 5.
    • C. The program runs fine but displays things other than 5.
    • D. The program does not compile because the compiler cannot distinguish which xmethod to invoke.

    我的答案: A

    9. (单选题)Suppose your method does not return any value, which of the following keywords can be used as a return type?

    • A. void
    • B. int
    • C. double
    • D. public
    • E. None of the above

    我的答案: A

    10. (单选题)The signature of a method consists of .

    • A. method name
    • B. method name and parameter list
    • C. return type, method name, and parameter list
    • D. parameter list

    我的答案: B

    11. (单选题)  is to implement one method in the structure chart at a time from the top to the bottom.

    • A. Bottom-up approach
    • B. Top-down approach
    • C. Bottom-up and top-down approach
    • D. Stepwise refinement

    我的答案: B

    12. (单选题)You should fill in the blank in the following code with .
    public class Test {
    public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5);

    System.out.print("The grade is "); printGrade(59.5);
    }

    public static printGrade(double score) { if (score >= 90.0) {
    System.out.println('A');
    }
    else if (score >= 80.0) { System.out.println('B');
    }
    else if (score >= 70.0) { System.out.println('C');
    }
    else if (score >= 60.0) { System.out.println('D');
    }
    else { System.out.println('F');
    }
    }
    }

    • A. int
    • B. double
    • C. boolean
    • D. char
    • E. void

    我的答案: E

    13. (单选题)When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as .

    • A. method invocation
    • B. pass by value
    • C. pass by reference
    • D. pass by name

    我的答案: B

    14. (单选题)All Java applications must have a method .

    • A. public static Main(String[] args)
    • B. public static Main(String args[])
    • C. public static void main(String[] args)
    • D. public void main(String[] args)
    • E. public static main(String[] args)

    我的答案: C

    15. (单选题)Analyze the following code.
    public class Test {
    public static void main(String[] args) { System.out.println(max(1, 2));
    }
    public static double max(int num1, double num2) { System.out.println("max(int, double) is invoked");

    if (num1 > num2) return num1;
    else
    return num2;
    }

    public static double max(double num1, int num2) { System.out.println("max(double, int) is invoked");

    if (num1 > num2) return num1;
    else
    return num2;
    }
    }

    • A. The program cannot compile because you cannot have the print statement in a non-void method.
    • B. The program cannot compile because the compiler cannot determine which max method should be invoked.
    • C. The program runs and prints 2 followed by "max(int, double)" is invoked.
    • D. The program runs and prints 2 followed by "max(double, int)" is invoked.
    • E. The program runs and prints "max(int, double) is invoked" followed by 2.

    我的答案: B

    16. (单选题)Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as
     , which stores elements in last-in first-out fashion.

    • A. a heap
    • B. storage area
    • C. a stack
    • D. an array

    我的答案: C

    17. (单选题)Analyze the following code:
    class Test {
    public static void main(String[] args) { System.out.println(xmethod(5));
    }

    public static int xmethod(int n, long t) { System.out.println("int");
    return n;
    }

    public static long xmethod(long n) { System.out.println("long");
    return n;
    }
    }

    • A. The program displays int followed by 5.
    • B. The program displays long followed by 5.
    • C. The program runs fine but displays things other than 5.
    • D. The program does not compile because the compiler cannot distinguish which xmethod to invoke.

    我的答案: B

    18. (单选题)A variable defined inside a method is referred to as .

    • A. a global variable
    • B. a method variable
    • C. a block variable
    • D. a local variable

    我的答案: D

    19. (单选题)(char)('a' + Math.random() * ('z' - 'a' + 1)) returns a random character 

    • A. between 'a' and 'z'
    • B. between 'a' and 'y'
    • C. between 'b' and 'z'
    • D. between 'b' and 'y'

    我的答案: A

    20. (单选题)Given the following method, what is the output of the call nPrint('a', 4)?
    static void nPrint(String message, int n) { while (n > 0) { System.out.print(message);
    n--;
    }
    }

    • A. aaaaa
    • B. aaaa
    • C. aaa
    • D. invalid call

    我的答案: D

    21. (单选题)Which of the following should be defined as a void method?

    • A. Write a method that prints integers from 1 to 100.
    • B. Write a method that returns a random integer from 1 to 100.
    • C. Write a method that checks whether a number is from 1 to 100.
    • D. Write a method that converts an uppercase letter to lowercase.

    我的答案: A

    22. (单选题)(int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number .

    • A. between 0 and (int)'z'
    • B. between (int)'a' and (int)'z'
    • C. between 'a' and 'z'
    • D. between 'a' and 'y'

    我的答案: B

    23. (单选题)Does the method call in the following method cause compile errors?
    public static void main(String[] args) { Math.pow(2, 4);
    }

    • A. Yes
    • B. No

    我的答案: B

    24. (单选题)(int)(Math.random() * (65535 + 1)) returns a random number .

    • A. between 1 and 65536
    • B. between 1 and 65535
    • C. between 0 and 65535
    • D. between 0 and 65536

    我的答案: C

    25. (单选题)Does the return statement in the following method cause compile errors?
    public static void main(String[] args) { int max = 0;
    if (max != 0) System.out.println(max); else
    return;
    }

    • A. Yes
    • B. No

    我的答案: B

    二. 多选题

    26. (多选题)The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as .

    • A. information hiding
    • B. encapsulation
    • C. method hiding
    • D. simplifying method

    我的答案: AB

  • 相关阅读:
    信息系统项目管理师---第十一章项目风险管理历年考题
    入门力扣自学笔记110 C++ (题目编号1374)
    使用verdaccio+docker搭建npm私有仓库以及使用
    信息通信企业开展数据安全管理工作的指引与实践
    每天一个数据分析题(三百九十二)- 多元线性回归
    linux如何创建文件
    SpringBoot打包成exe(别再用exe4j了,使用JDK自带工具)
    锐龙r5 6600u和r5 5600u区别 r56600u和r55600u对比
    SPDK block device及其编程的简单介绍
    C语言--用二分法快速计算指定整数的整数平方根
  • 原文地址:https://blog.csdn.net/x20020402/article/details/127398970
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号