问题 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. 基于Python操作ElasticSearch
  2. GPT v.s. 中国象棋:写过文章解过题,要不再来下盘棋?
  3. 像素游戏制作大师MV新手教程(二):素材的载入
  4. 7-9 职工排序题 (20 分)
  5. centos7安装python-pip
  6. 无代码iVX编程实现简单跳跃超级玛丽游戏
  7. javafx 调用java_Java验证(javafx)
  8. python3获取网页内容_python3获取一个网页特定内容
  9. 十大经典排序算法(动态演示+代码)
  10. sql 删除依赖_关系数据库标准语言SQL(二)
  11. 二.开发记录之派勤工控机远程使用和ubuntu和ROS环境配置
  12. 让我们一起Go(二)
  13. 细说php精要版 百度云,细说php精要版
  14. 浅谈分子动力学(MD)模拟及其势文件
  15. JavaScript - 将 Allegro 坐标文件转为嘉立创坐标文件(CSV 格式)的工具
  16. 【每日新闻】工信部部长苗圩:软件是新一代信息技术的灵魂
  17. Artifact在计算机视觉、图像处理领域的意思理解
  18. HDU_多重背包系列
  19. 应用程序无法正常启动(0xc000007b)
  20. DC-DC 保护调试经验

热门文章

  1. 全国大学计算机基础应用试题及答案,大学计算机基础试题题库(免费版,有答案的)...
  2. 【图像压缩】基于matlab香农熵和差分进化算法多级图像阈值图像压缩【含Matlab源码 2035期】
  3. 如何从身份证号中提取年月日
  4. 中小型企业网络局域网实例-交换机基础配置
  5. 2022危险化学品经营单位主要负责人考试题及模拟考试
  6. nvm和nrm的使用
  7. SpringCloud Alibaba
  8. Command line is too long. Shorten command line for
  9. php 以自动打字程序,利用vbs脚本实现自动打字
  10. tensorflow2.1.0 安装及GPU配置(Windows/Python)