Chatper 3 Discovering Classes and Object

  • Exercises:

  1.What is a class?

  A class is a template for manufacturing objects.

  2.How do you declare a class?

  By providing a header followed by a body.The header minimally consists of reserved word class followed by an identifier.The body consists of a sequence of declarations placed between a pair of brace characters.

  3.What is an object?

  An object is a named aggregate of code and data.

  4.How do you instantiate an object?

  By using the new operator followed by a constructor.

  5.What is a constructor?

  A constructor is a block of code for constructing an object by initializing it in some manner.

  6.True or false:Java creates a default noargument constructor when a class declares no constructors. true

  7.What is a paremeter list and what is a parameter?

  A parameter list is a round bracket-delimited and comma-separated list of zero or more parameter declarations.A parameter is a constructor or method variable that receives an expression value passed to the constructor or method when it calls.形参

  8.What is an argument list and what is an argument?

  An argument list is a round bracket-delimited and comma-separated list of zero or more expressions.An argument is one of these expressions whose value is passed to the correspongding parameter when a constructor or method variable is called.实参

  9.True or false:you invoke another constructor by specifying the name of class followed by an argument list.

  False,you invoke another constructor by specifying this followed by an argument list.

  10.Define arity.参数数量

  Arity is the number of arguments passed to a constructor or method or the number of operator operands.

  11.What is local variable?

  A local variable is a variabele that is declared in a constructor or method and is not a member of constructor or method parameter list.

  12.Define lifetime.

  Lifetime is a property of a variable that determines how long the variable exists.For example,local variable and parameters come into existence when a constructor or method is called and are destroyed when the cosntructor or method finishes.Similarly,an instance field comes into existence when an object is created and is destroyed when the object is garbage collected.

  13.Define scope.

  Scope is a property of variable that determines how accessible the variable is to code.For example,a parameter can be accessed only by the code within the constructor or method in which the parameter is declared.

  14.What is encapsulation?

  Encapsulation refers to the merging of state and behaviord into a single code entity.Instead of separating state and behaviors,which is done in structured programs,state and behaviors are combined into classe and object,which are the focus of object-based programs.

  15.Define field.

  A field is a variable declared within a class body.

  16.What is the difference between an instance field and a class field?

  An instance field describes some attribute of the real-world entity that an object is modeling and unique to each object, and a class field is identifies some data item that is shared by all object.

  17.What is a blank final and how does it differ from a true constant?

  A blank final is a real-only instance field.It differs from a true constant in that there are multiple copies of blank final (one per object) and only one true constant(one per class).

  18.How do you prevent a field from be shadowed?

  By changing the name of a same-named local variable or parameter or by qualifying the local variable's name or parameter's name with this or the class name followed by the the member access operator.

  19.Define method.

  A method is a named block of code declared within a class body.

  20.What is the difference between an instance method and a class method?

  An instance method describes some behavior of the real-world entity that an object is modeling and can access a specific object state,and a class method identifies some behavior that is common to all objects and can not access a specific object's state.

  21.Define recursion.

  Recursion is the act of a method invoking itself.

  22.How do you overload a method?

  You overload a method by introducing a method with the same name as an existing method but with a different parameter list into the same class.

  23.What is a class inistializer,and what is an instance initializer?

  A class inistializer is static-prefixed block that is introduced into a class body.An instance initializer is a block that is introduced into a class body as opposed to being introduced as the body of a method or a constructor.

  24.Define garbage collector.

  A garbage collector is code that runs in the background and occasionally checks for unreferenced object.

  25.True or false:String[] letters = new String[2]{"A","B"}; is correct syntax. False,remove "2"

  26.What is a ragged array?

  A ragged array is a two-dimensional array in which each row can have a different number of columns.

  • Summary:(省略)

Chapter 3 Discovering Classes and Object的更多相关文章

  1. TIJ——Chapter Seven:Reusing Classes

    Reusing Classes 有两种常用方式实现类的重用,组件(在新类中创建存在类的对象)和继承. Composition syntax Every non-primitive object has ...

  2. TIJ——Chapter Two:Everything Is an Object

    If we spoke a different language, we would perceive a somewhat different world. Ludwig Wittgenstein( ...

  3. TIJ——Chapter Ten:Inner Classes

    先提纲挈领地来个总结: 内部类(Inner Class)有四种: member inner class,即成员内部类.可以访问外部类所有方法与成员变量.生成成员内部类对象的方法:OuterClass. ...

  4. Think Python - Chapter 18 - Inheritance

    In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...

  5. Object Oriented Programming python

    Object Oriented Programming python new concepts of the object oriented programming : class encapsula ...

  6. JavaScript- The Good Parts Chapter 6

    Thee(你) I’ll chase(追逐:追捕) hence(因此:今后), thou(你:尔,汝) wolf in sheep’s array.—William Shakespeare, The ...

  7. Java提高学习之Object(5)

    字符串形式的表现 Q1:toString() 方法实现了什么功能?A1:toString() 方法将根据调用它的对象返回其对象的字符串形式,通常用于debug. Q2:当 toString() 方法没 ...

  8. 第三十二节,使用谷歌Object Detection API进行目标检测、训练新的模型(使用VOC 2012数据集)

    前面已经介绍了几种经典的目标检测算法,光学习理论不实践的效果并不大,这里我们使用谷歌的开源框架来实现目标检测.至于为什么不去自己实现呢?主要是因为自己实现比较麻烦,而且调参比较麻烦,我们直接利用别人的 ...

  9. Java:Object类详解

    Java的一些特性会让初学者感到困惑,但在有经验的开发者眼中,却是合情合理的.例如,新手可能不会理解Object类.这篇文章分成三个部分讲跟Object类及其方法有关的问题. 上帝类 问:什么是Obj ...

随机推荐

  1. Sublime Text 2 常用快捷键

    Sublime Text 2 常用的快捷键 (不包含插件快捷键) Ctrl+P 打开文件搜索框,可以直接输入文件名搜索,或者输入@funcName 可以直接到函数定义处,输入#key 可以直接查找,输 ...

  2. 软件工程 speedsnail 第二次冲刺1次

    20150518 完成任务:划线第一天,能画出一天连续的红线: 遇到问题: 问题1 线是弯曲的 解决1 没有解决 明日任务: 将线画直

  3. 判断字符串是否包含字母‘k’或者‘K’

    判断字符串是否包含字母‘k’或者‘K’ public bool IsIncludeK(string temp) { temp = temp.ToLower(); if (temp.Contains(' ...

  4. PHP-POSIX正则表达式函数

    1.ereg() 格式:ereg("条件",<原始字符串>) ereg()查找字符串,是严格区分大小写的 <?php $string="apples a ...

  5. linux中文显示乱码的解决办法

    linux中文显示乱码的解决办法 linux中文显示乱码是一件让人很头疼的事情. linux中文显示乱码的解决办法:[root@kk]#vi /etc/sysconfig/i18n将文件中的内容修改为 ...

  6. Ubuntu10.10的网络配置

    有一阵子着实对Ubuntu的网络配置很迷惑,耐下心来仔细上网找了找,有点小心得,总结一下. 先说下大概的配置过程,再去细究一些情况. 一.配置大概分三类:通过配置文件配置.通过命令配置.通过图形化的网 ...

  7. linux资源监控命令详解

    Linux统计/监控工具SAR详细介绍:要判断一个系统瓶颈问题,有时需要几个 sar 命令选项结合起来使用,例如: 怀疑CPU存在瓶颈,可用 sar -u 和 sar -q deng 等来查看 怀疑内 ...

  8. 复习后台代码(与前面clentHttp连接网络结合)

    package com.zzw.LoginServelt; import java.io.IOException; import java.io.PrintWriter; import javax.s ...

  9. 【转】代码编辑器(二)-SynEdit

    在我去年的时候我就有这个了,而且这是我第二个第三方的控件(第一个是DevExpress),这个是专门做代码编辑器的.安装方法:点我. 安装成功了之后,会在Tool Palette看到两个:SynEdi ...

  10. SHOW SLAVE STATUS几个常见参数

    --显示当前读取的Master节点二进制日志文件和文件位置,对应线程I/O thread Master_Log_File: mysql-bin.000011 Read_Master_Log_Pos: ...