问题 1

Analyze the following code.

public class Test {int x;public Test(String t) {System.out.println("Test");}public static void main(String[] args) {Test test = new Test();System.out.println(test.x);}
}

A.The program has a compile error because x has not been initialized.

B.The program has a compile error because you cannot create an object from the class that defines the object.

C.The program has a compile error because Test does not have a default constructor.

D.The program has a compile error because System.out.println method cannot be invoked from the constructor.

问题2

The java.util.Date class is introduced in this section. Analyze the following code and choose the best answer:

Which of the following code in A or B, or both creates an object of the Date class:

A:

public class Test {public Test() {new java.util.Date();}
}

B:

public class Test {public Test() {java.util.Date date = new java.util.Date();}
}

A.A.

B.Neither

C.B.

问题 3

What code may be filled in the blank without causing syntax or runtime errors:

public class Test {java.util.Date date;public static void main(String[] args) {Test test = new Test();System.out.println(_________________);}
}

A.test.date

B.test.date.toString()

C.date.toString()

D.date

问题 4

What is the output of the following program?

import java.util.Date;
public class Test {public static void main(String[] args) {Date date = new Date(1234567);m1(date);System.out.print(date.getTime() + " ");m2(date);System.out.println(date.getTime());}public static void m1(Date date) {date = new Date(7654321);}public static void m2(Date date) {date.setTime(7654321);}
}

A.7654321 7654321

B.7654321 1234567

C.1234567 1234567

D.1234567 7654321

问题 5

What is the value of myCount.count displayed?

public class Test {public static void main(String[] args) {Count myCount = new Count();int times = 0;for (int i=0; i<100; i++)increment(myCount, times);System.out.println("myCount.count = " + myCount.count);System.out.println("times = "+ times);}public static void increment(Count c, int times) {c.count++;times++;}
}
class Count {int count;Count(int c) {count = c;}Count() {count = 1;}
}

A.101

B.99

C.98

D.100

问题 6

What is wrong in the following code?

class TempClass {int i;public void TempClass(int j) {int i = j;}
}
public class C {public static void main(String[] args) {TempClass temp = new TempClass(2);}
}

A.The program has a compilation error because TempClass does not have a default constructor.

B.The program compiles and runs fine.

C.The program has a compilation error because TempClass does not have a constructor with an int argument.

D.The program compiles fine, but it does not run because class C is not public.

问题 7

A constructor can access ___________.

A.A public instance variable

B.A private instance variable

C.A local variable defined in any method

D.A static variable

问题 8

A method that is associated with an individual object is called __________.

A.a class method

B.an object method

C.a static method

D.an instance method

问题 9

All local variables in a method have default values.

A.false

B.true

问题 10

An object is an instance of a __________.

A.class

B.program

C.data

D.method

问题 11

Analyze the following code.

public class Test {int x;public Test(String t) {System.out.println("Test");}public static void main(String[] args) {Test test = null;System.out.println(test.x);}
}

A.The program has a runtime NullPointerException because test is null while executing test.x.

B.The program has a compile error because Test does not have a default constructor.

C.The program has a compile error because x has not been initialized.

D.The program has a compile error because test is not initialized.

E.The program has a compile error because you cannot create an object from the class that defines the object.

问题 12

Analyze the following code:

class Test {private double i;public Test(double i) {this.t();this.i = i;}public Test() {System.out.println("Default constructor");this(1);}public void t() {System.out.println("Invoking t");}
}

A.this.t() may be replaced by t().

B.this(1) must be replaced by this(1.0).

C.this(1) must be called before System.out.println("Default constructor").

D.this.i may be replaced by i.

问题 13

Analyze the following code:

public class Test {public static void main(String[] args) {A a = new A();a.print();}
}
class A {String s;A(String s) {this.s = s;}void print() {System.out.println(s);}
}

A.The program compiles and runs fine and prints nothing.

B.The program has a compilation error because class A does not have a default constructor.

C.The program would compile and run if you change A a = new A() to A a = new A("5").

D.The program has a compilation error because class A is not a public class.

问题 14

Given the declaration Circle x = new Circle(), which of the following statement is most accurate?

A.x contains an int value.

B.You can assign an int value to x.

C.x contains a reference to a Circle object.

D.x contains an object of the Circle type.

问题 15

Which of the following statements are true?

A.At least one constructor must always be defined explicitly.

B.The default constructor is a no-arg constructor.

C.A default constructor is provided automatically if no constructors are explicitly declared in the class.

D.Every class has a default constructor.

问题 16

You can access a class variable using a syntax like objectName.classVariable or ClassName.classVariable.

A.false

B.true

问题 17

You use the _________ operator to access members of an object.

A..

B.*

C.()

D.%

问题 18

________ is invoked to create an object.

A.The main method

B.A method with the void return type

C.A constructor

D.A method with a return type

问题 19

__________ represents an entity in the real world that can be distinctly identified.

A.A method

B.A data field

C.A class

D.An object

自用 | bb选择题 assgn1(chapter09 对象和类)相关推荐

  1. java 的对象类用_java基础(第零篇)对象与类

    前言: 本文讲述java中对象与类的一些概念.包括对象与类的有关概念,类间五种关系,类的访问权限等. 在java中,一切都可以用对象来描述,操作对象的标识符只不过是对象的一个引用,一个对象可以有多个引 ...

  2. python对象包括哪些,Python | 对象和类

    Python之对象和类 1. 什么是对象 2. 使用class定义类 如果把类比作塑料盒子,类则像是制作和自用的模具.例如,Python的内置类String可以创建像'cat'和'duck'这样的字符 ...

  3. 客快物流大数据项目(五十六): 编写SparkSession对象工具类

    编写SparkSession对象工具类 后续业务开发过程中,每个子业务(kudu.es.clickhouse等等)都会创建SparkSession对象,以及初始化开发环境,因此将环境初始化操作封装成工 ...

  4. Java 对象和类 的理解

    学而时习之,温故而知新. 对象: 对象是类的一个实例,有状态和行为 类: 类为对象定义属性和行为 识别对象和类, 自己的的知识里面 一般 new 之后的是对象, class后面的是类 对象的特征: 1 ...

  5. Swift中文教程(五)--对象和类

    原文:Swift中文教程(五)--对象和类 Class 类 在Swift中可以用class关键字后跟类名创建一个类.在类里,一个属性的声明写法同一个常量或变量的声明写法一样,除非这个属性是在类的上下文 ...

  6. js之数组,对象,类数组对象

    2019独角兽企业重金招聘Python工程师标准>>> 许久不写了,实在是不知道写点什么,正好最近有个同事问了个问题,关于数组,对象和类数组的,仔细说起来都是基础,其实都没什么好讲的 ...

  7. Java学习_day008面向对象(OOP):对象和类

    面向对象:OO 面向对象的分析:OOA 面向对象的设计:OOD 面向对象分析与设计:OOAD--目标 面向对象的编程:OOP--起始点 高质量代码的要求(OO终极目标):复用性好.拓展性好.维护性好. ...

  8. 【学习笔记】【oc】类和对象及类的三大基本特征

    1.类和对象 类是抽象化,对象是具体化. (1)定义类: 分为两个步骤,类的声明:定义类的成员变量和方法:@interface 用于声明定义类的接口部分,@end表面定义结束:. 成员变量的定义:{} ...

  9. javascript对象、类与原型链

    js是一个基于对象的语言,所以本文研究一下js对象和类实现的过程和原理. 对象的属性及属性特性 下面是一个对象的各个部分: var person = {name: "Lily",a ...

最新文章

  1. scala 处理 Response返回 时间报错问题
  2. 随机森林案例分析:德国银行信贷风险分析
  3. nova resize代码调用部分分析
  4. MySQL - 高效的设计MySQL库表
  5. Android ListView侧滑item,仿QQ删除效果
  6. CSS margin 外边距 属性的位置关系
  7. JDK8新特性(十五)之重复注解、类型注解
  8. linux子网掩码和ip计算,子网掩码的计算 - winglok的个人页面 - OSCHINA - 中文开源技术交流社区...
  9. 第三章项目管理过程重点--转载
  10. 智慧城市综合管控平台
  11. Linux中etc目录etc是什么单词的缩写
  12. android编码技巧_我如何使用编码技巧使航空公司取代丢失的婴儿车
  13. [PPPOE]PPPD源码分析
  14. 最基础且详细的 RPCA-ALM 算法推导过程(手写稿)
  15. Field accountDao in com.mdxl.service.AccountService required a bean of type 'com.mdxl.dao.MbAccountD
  16. 发现微型计算机染有病毒后,??发现微型计算机染有病毒后,较为彻底的清除方法是(?? )...
  17. Linux C 编程内存泄露检测工具(二):memwatch
  18. CSS 滚动条样式修改(详细)
  19. python T检验
  20. Git连接oschina管理代码版本

热门文章

  1. 防御云服务器被攻击的三个方法
  2. OpenCL和CUDA全解释
  3. 工业互联网平台发展概况
  4. day8--by a gentlement man
  5. matlab 基础绘图——随机雪景绘制
  6. 高数_证明_介值定理
  7. 快来个大佬指点一下,求求了。
  8. AE加载不同数据的方法
  9. 数据库学习笔记第三弹——MySQL常用的图形化管理辅助工具及相关问题(图文详解2022))
  10. 用于MRI自动化测试设备的定制微波MUX开关