/*Chapter4习题
(1) 用默认构建器创建一个类(没有自变量),用它打印一条消息。创建属于这个类的一个对象。
(2) 在练习1 的基础上增加一个过载的构建器,令其采用一个String 自变量,并随同自己的消息打印出来。
(3) 以练习2 创建的类为基础上,创建属于它的对象句柄的一个数组,但不要实际创建对象并分配到数组
122
里。运行程序时,注意是否打印出来自构建器调用的初始化消息。
(4) 创建同句柄数组联系起来的对象,最终完成练习3。*/
import java.util.*;
class DefaultConstru {
//无参数构造方法
DefaultConstru() {
System.out.println("From Default Construction");
}
//带有一个参数的构造方法
DefaultConstru(String s) {
System.out.println("From arg of String Construction ,arg is: " + s);
}
//成员变量
int memberVar;
public static void main(String [] args) {
DefaultConstru dd = new DefaultConstru();
DefaultConstru dc = new DefaultConstru("cc");
//初始化一个类DefaultConstru的对象句柄组
DefaultConstru [] arrayDefault = new DefaultConstru[20];
Random rand = new Random();
for(int i = 0; i < arrayDefault.length ; i ++) {
//为每一个对象句柄初始化
arrayDefault[i] = new DefaultConstru();
//为成员变量赋值
arrayDefault[i].memberVar = Math.abs(rand.nextInt())% 500 + 1;
//将成员变量的值输出
// System.out.println("arrayDefault[" + i + "].memberVar = " + arrayDefault[i].memberVar);
//将数组中每一个值输出,不知道输出的是什么
System.out.println("arrayDefault[" + i + "] = " + arrayDefault[i]);
}
}
}
输出结果为:
但不太清楚最后一条输出语句输出的到底是什么东西,那位TX知道啊?
分享到:
相关推荐
这篇文档是针对“朗文英语1b chapter 4”的一项练习,目的是帮助学习者提高英语动词时态理解和应用能力,特别是现在进行时。现在进行时表示当前正在进行的动作,结构为"be + 动词-ing"。 在练习题的第一部分,需要...
Chapter 4:Approaches to Programming Problems Chapter 5:Linked Lists Chapter 6:Trees and Graphs Chapter 7:Arrays and Strings Chapter 8:Recursion Chapter 9:Sorting Chapter 10:Concurrency Chapter 11:...
Chapter 4: 文件和目录 Chapter 5: 标准 I/O 库 Chapter 6: 系统数据文件和信息 Chapter 7: 进程环境 Chapter 8: 进程控制 Chapter 9: 进程关系 Chapter 10: 信号 Chapter 11: 线程 Chapter 12: 线程控制 Chapter 13...
Chapter 4: Factory Method Chapter 5: Abstract Factory Chapter 6: Builder Chapter 7: Singleton Chapter 8: Adapter Chapter 9: Bridge Chapter 9: Bridge Chapter 11: Mediator Chapter 12: Observer Chapter ...
Chapter 4: Procedures and Functions Chapter 5: Arrays and Records Chapter 6: All About Strings Part II Chapter 7: Objects Chapter 8: Inheritance Chapter 9: Handling Exceptions Chapter 10: Properties ...
这篇文档是针对“朗文英语1b chapter 4”的练习材料,主要涵盖了英语的基本语法和词汇,特别是关于现在进行时态的使用。现在进行时态表示当前正在进行的动作,通常由"be"动词(am/is/are)加动词的现在分词形式构成...
Chapter 4: Analytics in Social Media Chapter 5: Dedicated vs. Hybrid Tools Chapter 6: Alexander and Frederik Peiniger Part III: Differences of Social Media Networks Chapter 7: Social Network ...
Chapter 4: Existing Applications That Use TPMs Chapter 5: Navigating the Specification Chapter 6: Execution Environment Chapter 7: TPM Software Stack Chapter 8: TPM Entities Chapter 9: Hierarchies ...
Chapter 4: Demand Management Chapter 5: Configurator Chapter 6: Sales Order Processing Chapter 7: Time Management Chapter 8: Project Management Chapter 9: Maintenance Management Chapter 10: Field ...
CHAPTER 4:Files and File System Structure CHAPTER 5:File Security CHAPTER 6:Basic File Processing CHAPTER 7:Advanced File Processing CHAPTER 8:File Sharing CHAPTER 9:Redirection and Piping CHAPTER 10:...
Chapter 4: Fundamentals of Django App Design Chapter 5: Settings and Requirements Files Chapter 6: Model Best Practices Chapter 7: Queries and the Database Layer Chapter 8: Function- and Class-Based ...
Chapter 4: Debugging Techniques Chapter 5: Concurrency and Race Conditions Chapter 6: Advanced Char Driver Operations Chapter 7: Time, Delays, and Deferred Work Chapter 8: Allocating Memory ...
Chapter 4: Home Page #1 Data Chapter 7: Transposed Probabilities Data Chapter 7: New Probabilities Data Chapter 9: Head First Data Analysis R Script Chapter 9: Raise Data Chapter 10: New Raise Data ...
Chapter 4: Training Linear Models Chapter 5: Support Vector Machines Chapter 6: Decision Trees Chapter 7: Ensemble Learning and Random Forests Chapter 8: Dimensionality Reduction Chapter 9: Up and ...
Chapter 4: Deep Dive into Kafka Consumers Chapter 5: Building Spark Streaming Applications with Kafka Chapter 6: Building Storm Applications with Kafka Chapter 7: Using Kafka with Confluent Platform ...
CHAPTER 4: THE FILESYSTEM CHAPTER 5: THE SHELL PART II: THE EDITORS CHAPTER 6: THE VIM EDITOR CHAPTER 7: THE EMACS EDITOR PART III: THE SHELLS CHAPTER 8: THE BOURNE AGAIN SHELL (bash) CHAPTER 9: THE...
Chapter 4: Working With Collections Chapter 5: Higher-Order Functions Chapter 6: Recursions And Reductions Chapter 7: Additional Tuple Techniques Chapter 8: The Itertools Module Chapter 9: More ...
chapter4:两阶经典检测器:Faster RCNN chapter5:单阶多层检测器:SSD chapter6:单阶经典检测器:YOLO chapter7:模型加速之轻量化网络 chapter8:物体检测细节处理 chapter9:物体检测难点 chapter10:物体检测...