First write(JAVA面向对象编程)

1.二维数组是由若干个一维数组组成的一维数组,他的每一个元素都是一个一维数组。

2.for~each

*for(数据类型 变量 :数组)

语句;

*例如:for(int element : array)

System.out.println(element);

他会打印数组array中的每一个元素。

3.clone的用法

*相当于复制一个数组,例如:

int a[]={1,2,3,4,5};

int [] b=(int [])a.clone 得到一个与a数组相同的 数组b(二维数组也一样)。

4.静态变量与非静态变量的区别:

*非静态变量单独属于某个对象

*静态变量属于整个类

5.所有的对象都是实例成员变量,如果所属的对象没有被创   建,它们就不存在。如果外部使用它,需要先创建一个对 象,然后通过“对象名。变量名”来访问。

6.方法的调用:

*如果方法是被static修饰(静态方法)则可以用

类名.方法名 来调用

*否则就创建一个对象,用 对象名. 方法名 来调用

7.基本类型作为方法调用的参数:

*它所传递的实参的值是一个副本

*单值传递。实参本质上是一个可求值的表达式,它所求 出来的值是一个基本类型

*单向传递。方法内部可以修改形参的值,但这种修改不 会影响到对应的实参。

8.构造方法:

//是对象中第一个被执行的方法,主要用于申请内存, 对类 的成员变量进行初始化等操作。

*构造方法名称必须和类的名称完全相同。

*构造方法不能用static,final来修饰。一般也不用 private修饰,这会导致无法在外部创建对象。

*构造方法不能由对象显式的调用。一般通过new关键字 来调用,或者用this,super来调用。

9.静态方法与实例方法的区别

*在外部调用静态方法,用类名.方法名,也可以用

对象名.方法名。实例方法只有后面的方式,也就是说 用静态方法无需创建对象。

*静态方法在访问本类的成员时,只允许访问静态成员静 态成员(即静态成员变量和静态方法),而不允许成员 变量和实例方法;实例方法则无此限制。

10.子类对父类的继承:

*【修饰类符】class 子类名 extends 父类名{

类体

}

11.子类方法的访问权限与父类的不相同,但是只允许更宽 松,而不允许更严格。

12.Final修饰的方法是一个最终方法,他的子类不能覆盖该 方法。反之一个非最终方法,可以在子类中指定final 修饰符,将其变成最终方法。

Java规定,静态方法不允许被实例方法覆盖,同样,实 例方法也不允许被静态方法覆盖。也就是说,不允许出现 父类方法和子类方法覆盖时static修饰符发生变化。

13.使用super时:

*它只能同在构造方法中。

*他只能是第一条执行语句。

*一个构造方法中只能有一条super语句。

14.JAVA中实现重载的方法:

*在同一类中

*方法名称相同,参数不同

15.构造方法的重载:

相对于普通的成员方法,由于构造方法不能是static和 final类型,而且没有返回值,所以它比普通成员方 法更简单一些

16.重载参数的转换两条路径:

*byte→short→int→long→float→double

*char→int→long→float→double

17.重载与覆盖的区别:

*重载和覆盖的方法名称都相同,但重载要求参数列表不 同,而覆盖则要求参数列表完全相同。

*重载对于方法前面的修饰没有限制,而覆盖则对这些修 饰符的使用有限制。

*同一类中的方法能够相互重载,但不能相互覆盖。子类 对父类方法既可以冲在也可以覆盖。

*重载时,编译器在编译期间可以确定调用哪一个方法, 而覆盖则有可能在运行期间在可以确定。

 

 

Write a class called Person with the following attributes: title (Mr., Mrs., Ms., etc.) first name last name nickname age in years sex (boolean - true/false to indicated either male or female) Write a constructor that takes no parameters and performs no initializations. Write a constructor that takes a parameter for each of the attributes listed above and sets them within the objects by calling the setter methods listed below. The Person class should have a setter method and a getter method with public access for each attribute. In the setter methods, get rid of any leading or trailing spaces (String trim() method). For a Person with the following attributes: title = "Mr." first name = "Michael" last name = "Zheng" nickname = "Mike" age = 22 sex = true (true is male, false is female) The Person class should have the following public access methods that return Strings as follows: standardName() concatenation of the first and last names (i.e., "Michael Zheng") formalName() concatenation of the title, first name, lastname (i.e., "Mr. Michael Zheng") casualName() return the nickname if it is not null, otherwise return the first name (i.e., "Mike") Be realistic when generating names. If a particular attribute does not exist for a given person, don't try to concatenate it. If necessary, add appropriate spacing and punctuation, but do not leave any leading or trailing spaces in the String that is returned. MakePerson Write a class called MakePerson with a main() method that instantiates 2 Person objects. Initialize the attributes of one of the Person objects by supplying parameters to it's constructor. Instantiate the other Person object with the default constructor (that does not accept any parameters), then set it's attributes via the appropriate setter methods. For each of the Person objects, execute and print (System.out.println()) the results of all of the getter methods and of the standardName(), formalName(), and casualName() methods.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值