zoukankan      html  css  js  c++  java
  • Chapter 3 Discovering Classes and Object

    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:(省略)
  • 相关阅读:
    HDU 5977 Garden of Eden(点分治求点对路径颜色数为K)
    HDU 5828 Rikka with Sequence(线段树区间加开根求和)
    TZOJ 1689 Building A New Barn(求平面上有几个其它点求到n个点的曼哈顿距离最小)
    HDU 5734 Acperience(数学推导)
    POJ 1741 Tree(点分治点对<=k)
    HDU 5723 Abandoned country(kruskal+dp树上任意两点距离和)
    HDU 5988 Coding Contest(最小费用最大流变形)
    TZOJ 1693 Silver Cow Party(最短路+思维)
    TZOJ 4602 高桥和低桥(二分或树状数组+二分)
    TZOJ 2099 Sightseeing tour(网络流判混合图欧拉回路)
  • 原文地址:https://www.cnblogs.com/allenpengyu/p/3589593.html
Copyright © 2011-2022 走看看