java face questions base portion 2

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/hardtomakeaname/article/details/102726594

A .hashCode () and equals ()

1.hashCode () and equals () is the object of intrinsic properties

equals () obtained the address of the object hashcode () I think the draw is the integer value corresponding to the address of the object

2. provisions: equals () equal to two objects, hashcode () must be equal;

   hashcode () are equal, equals () may be equal or may vary. 

3. For String, he rewrote the equals () and hashCode (). .

E.g:

String s1=new String("nishizhu");

String s2=new String("nishizhu");

Both of them are s1 == s2

equals now changed to the comparison values ​​are the same, but in fact they are not stored in the same address, so you must override hashcode.

Two: the three characteristics of java

1. Packaging

That is the objective things packaged as an abstract class

Package is mounted properties and methods to a single class.

The purpose is to simplify programming and security, you do not know me there details you through the interface used on the line

2. Inheritance

 

Inheritance is that a subclass inherits characteristics and behavior of the parent class, the subclass has methods and properties of the parent class

 

3. Polymorphism

Polymorphism is the ability to have several different forms or manifestations of the same behavior.

Polymorphism is the same interface, a different instance perform different operations, as shown:

 

Specific performance is when using the upward transition ah. . Is the parent class reference can hold subclass object. Then the parent class reference to the parent class can only use some method, and when the call is transferred out of the subclasses rewritten

 

 

Method three like .Object

1.getcCass () method

getClass () Returns the runtime class of an object, such as:

Class a = target .getClass (); // get a bytecode file a.getName the object () to get the name

2.equals()

3.hashcode()

4.toString () method:

Object class toString method returns a string name of the class (an object is an instance of the class), unsigned at marker "@" and the object hash code hexadecimal representation consists of

5.notify () wake up a single thread waiting on this object's monitor

6.notifyAll () wakes up all threads waiting on this object's monitor

7.wait () causes the current thread to wait

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/hardtomakeaname/article/details/102726594