slug
type
status
category
summary
date
tags
password
icon

Key Points and Sample Codes

  1. Objects: Instances of Classes (2.1)
      • Key Points: Objects are instances of classes, encapsulating data and methods that operate on data.
      • Sample Code:
    1. Creating and Storing Objects (Instantiation) (2.2)
        • Key Points: Objects are created using the new keyword and stored in variables.
        • Sample Code:
      1. Calling a Void Method (2.3)
          • Key Points: Void methods perform actions but do not return a value.
          • Sample Code:
        1. Calling a Void Method with Parameters (2.4)
            • Key Points: Methods can accept parameters to customize their behavior.
            • Sample Code:
          1. Calling a Non-void Method (2.5)
              • Key Points: Non-void methods return a value.
              • Sample Code:
            1. String Objects: Concatenation, Literals, and More (2.6)
                • Key Points: Strings can be concatenated using +, and literals are defined using double quotes.
                • Sample Code:
              1. String Methods (2.7)
                  • Key Points: String class provides methods like length(), substring(), indexOf().
                  • Sample Code:
                1. Wrapper Classes: Integer and Double (2.8)
                    • Key Points: Wrapper classes provide a way to use primitive data types as objects.
                    • Sample Code:
                  1. Using the Math Class (2.9)
                      • Key Points: The Math class provides methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
                      • Sample Code:

                    20 AP Style MCQs

                    1. Which of the following is used to create a new object in Java?
                        • A) new
                        • B) class
                        • C) newClass
                        • D) instance
                    1. What will the following code print?
                        • A) Test
                        • B) obj
                        • C) Hello World
                        • D) Nothing
                    1. What is the output of the following code?
                        • A) Java Programming
                        • B) JavaProgramming
                        • C) Java
                        • D) Programming
                    1. What does the following method return type signify?
                        • A) Returns an integer
                        • B) Returns nothing
                        • C) Returns a string
                        • D) Returns a boolean
                    1. Which method would you use to determine the length of the string "APCSA"?
                        • A) getLength()
                        • B) length()
                        • C) size()
                        • D) lengthOf()
                    1. What will be the output of the following Java code snippet?
                        • A) True
                        • B) False
                        • C) Error
                        • D) None of the above
                    1. What is the result of the following expression in Java?
                        • A) 6
                        • B) 8
                        • C) 5
                        • D) 9
                    1. In Java, which of the following can be used to concatenate two strings?
                        • A) +
                        • B) append()
                        • C) concatenate()
                        • D) attach()
                    1. How can you create a string that represents the name "John Doe" using string literals?
                        • A) String name = "John" + "Doe";
                        • B) String name = "John" + " " + "Doe";
                        • C) String name = "John, Doe";
                        • D) String name = "John-Doe";
                    1. Which method of the String class returns the position of the first occurrence of a specified character string in a String?
                        • A) find()
                        • B) search()
                        • C) locate()
                        • D) indexOf()
                    1. Consider the following Java class:
                      1. What is the correct way to call the start method on an object of Vehicle named myCar?
                        • A) Vehicle.start();
                        • B) Vehicle myCar = start();
                        • C) myCar.start();
                        • D) start(myCar);
                    1. If you create a String object as follows:
                      1. What is the result of greeting.length()?
                        • A) 12
                        • B) 13
                        • C) 14
                        • D) An error occurs
                    1. Which of the following code snippets correctly creates an Integer object representing the number 42?
                        • A) Integer num = new Integer("42");
                        • B) Integer num = Integer.valueOf("42");
                        • C) Integer num = 42;
                        • D) All of the above
                    1. What is the return type of the Math.abs() method when passed an integer argument?
                        • A) int
                        • B) double
                        • C) long
                        • D) float
                    1. What is the purpose of the void keyword in a method declaration?
                        • A) Indicates that the method returns no value
                        • B) Declares a variable inside the method
                        • C) Makes the method invisible to other classes
                        • D) None of the above
                    1. Which of the following is a correct way to use the Math.random() method to generate a random integer between 0 and 99?
                        • A) (int) (Math.random() * 100)
                        • B) (int) (Math.random() * 99)
                        • C) (Math.random() * 99)
                        • D) Math.random(100)
                    1. In Java, what does the String method substring(1, 4) return when called on the string "example"?
                        • A) "xam"
                        • B) "xamp"
                        • C) "exam"
                        • D) "xample"
                    1. What will be the result of executing the following code segment?
                        • A) true
                        • B) false
                        • C) Error
                        • D) None of the above
                    1. How can you convert a double to a String in Java?
                        • A) String.valueOf(double)
                        • B) Double.toString(double)
                        • C) double.toString()
                        • D) Both A and B are correct
                    1. Which wrapper class method is used to parse a String into an Integer?
                        • A) Integer.parseInt()
                        • B) Integer.valueOf()
                        • C) Integer.toString()
                        • D) Integer.parseString()
                    Answers to MCQs
                    1. A
                    1. C
                    1. A
                    1. B
                    1. B
                    1. B
                    1. B
                    1. A
                    1. B
                    1. D
                    1. C
                    1. B
                    1. D
                    1. A
                    1. A
                    1. A
                    1. A
                    1. B
                    1. D
                    1. A
                     
                    第6题解析:
                    输出结果为 false
                    原因如下:
                    • 使用 new 关键字会每次创建一个新的对象,因此 num1num2 分别指向两个不同的 Integer 实例,即使它们存储的值都是 100。
                    • == 操作符比较的是对象的引用,也就是它们是否指向同一个内存地址,而不是比较对象内部的值。
                    • 如果想比较两个对象的值是否相等,可以使用 equals() 方法,比如 num1.equals(num2),这样会返回 true
                     
                     
                    第18题解析:
                    这段代码会输出 false
                    解释:
                    • str1 使用字符串字面量 "test",该字符串会被存储在 Java 的字符串常量池中。
                    • str2 使用 new String("test") 创建,这会在堆内存中创建一个新的字符串对象,而不是使用常量池中的对象。
                    • == 运算符比较的是两个对象的引用是否相同,而不是它们的内容。由于 str1str2 指向的是不同的对象,所以 str1 == str2 的结果是 false
                     
                     
                    CSA UNIT 1: Primitive TypesCSA UNIT 3: Boolean Expressions and if Statements
                    Loading...
                    现代数学启蒙
                    现代数学启蒙
                    推广现代数学🍚
                    最新发布
                    Java Quick Reference
                    2025-2-14
                    CSA UNIT 4: Iteration
                    2025-2-13
                    CSA UNIT 3: Boolean Expressions and if Statements
                    2025-2-13
                    CSA UNIT 2: Using Objects
                    2025-2-13
                    CSA Unit 5: Writing Classes
                    2025-2-13
                    2025 CSA  Quick Review
                    2025-2-11
                    公告
                    🎉现代数学启蒙(MME:Modern Mathematics Enlightenment)欢迎您🎉
                    -- 感谢您的支持 ---