JHTP自测题_第三章_类、对象、方法及字符串简介

Self-Review Exercises
3.1 Fill in the blanks in each of the following:
a) Each public class declaration that begins with keyword must be stored in a file that has exactly the same name as the class and ends with the .java filename extension.
b) Keyword class in a class declaration is followed immediately by the class’s name.
c) Keyword new requests memory from the system to store an object, then calls the corresponding class’s constructor to initialize the object.
d) Each parameter must specify both a(n) type and a(n) name .
e) By default, classes that are compiled in the same directory are considered to be in the same package, known as the default package.
f) Java provides two primitive types for storing floating-point numbers in memory: float and double.
g) Variables of type double represent double-decision floating-point numbers.
h) Scanner method nextDouble returns a double value.
i) Keyword public is an access modifier.
j) Return type void indicates that a method will not return a value.
k) Scanner method nextLine reads characters until it encounters a newline character, then returns those characters as a String.
l) Class String is in package java.lang .
m) A(n) import declaration is not required if you always refer to a class with its fully qualified class name.
n) A(n) floating-point number is a number with a decimal point, such as 7.33, 0.0975 or 1000.12345.
o) Variables of type float represent single-precision floating-point numbers.
p) The format specifier %f is used to output values of type float or double.
q) Types in Java are divided into two categories— primitive types and reference types.
3.2 State whether each of the following is true or false. If false, explain why.
a) By convention, method names begin with an uppercase first letter, and all subsequent words in the name begin with a capital first letter. (False)
b) An import declaration is not required when one class in a package uses another in the same package. (True)
c) Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task. (True)
d) A primitive-type variable can be used to invoke a method. (False)
e) Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class. (False)
f) Every method’s body is delimited by left and right braces ({ and }). (True)
g) Primitive-type local variables are initialized by default. (False. Primitive-type instance variables are initialized by default. Each local variable must explicitly be assigned a value.)
h) Reference-type instance variables are initialized by default to the value null. (True)
i) Any class that contains public static void main(String[] args) can be used to execute an app. (True)
j) The number of arguments in the method call must match the number of parameters in the method declaration’s parameter list. (True)
k) Floating-point values that appear in source code are known as floating-point literals and are type float by default. (False)
3.3 What is the difference between a local variable and an instance variable?
A local variable is declared in the body of a method and can be used only from the point at which it’s declared through the end of the method declaration. An instance variable is declared in a class, but not in the body of any of the class’s methods. Also, instance variables are accessible to all methods of the class. (We’ll see an exception to this in Chapter 8.)
3.4 Explain the purpose of a method parameter. What is the difference between a parameter and an argument?
**A parameter represents additional information that a method requires to perform its task.
Each parameter required by a method is specified in the method’s declaration. An argument is the actual value for a method parameter. When a method is called, the argument values are passed to the corresponding parameters of the method so that it can perform its task.**

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值