Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the grammar rules of JAVA

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I would like to share with you the relevant knowledge points of JAVA grammar rules, which are detailed in content and clear in logic. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

/ / Polymorphism

Definition: refers to a real column in which a polymorphic reference can point to multiple classes; Java implements polymorphism through method rewriting and method overloading

/ / extends

Create a subclass of a class by adding an extends clause to the class declaration

Subclasses can inherit member variables and methods with access set to public,protected,friendly in the parent class, but cannot inherit member variables and methods with access permissions of private.

/ / final class

The final class cannot be inherited

If you think that the definition of a class is perfect and you no longer need to generate its subclasses, you should also modify it as a final class

Final class classname {...}

/ / abstract class

The abstract class must be inherited and the method must be overloaded; it should not be enumerated as an object; number is an abstract class

/ / java.lang.object class

1.equals (): compare the same state and function

Integer one = new Integer (1), anotherOne = new Integer (1)

If (one.equal (anotherOne)) {

System.pringln ("objects are equal");} / / return true

2.getClass ()

It's final method.

Void printClassName (object obj)

{

System.out.println ("The object's class is"

"+ obj.getClass () .getName ()

)

Create an instance of a class, and the object created can be any class

Object createNewInstanceof (object obj)

{

Retuen obj.getClass () .newInstance ()

}

3.toString ()

Returns a string representation of the object

System.out.println (Thread.currentThread () .toString ())

4.finalize ()

5.notify (), notifyAll (), wait () are used for synchronization in multithreading

/ / member variable

A static: class variable B final: constant C volatile: shared variable

/ / member method

A static: can reference (class member) without instantiation, others are (instance member); B abstrace and final, whether they can be overloaded (yes and no); C native: integrate java code with code from other languages; D synchronized: control the access of multiple concurrent threads to shared data; E throwsExceptionList: out-of-column processing; F this: reference the current object

G super: refers to the parent class of the current object, its usage:

(1) super.variable / / is used to access the hidden member variable of the parent class (2) super.Method ([paramlist]) / / to call the overloaded method in the parent class; (3) super. ([paramlist]) / / call the constructor in the parent class. In the class method (static), you cannot use the this or super modifier.

/ / interface

Is a collection of method definitions and constant values

A can realize the same behavior of unrelated classes through the interface without considering the hierarchical relationship between these classes; B can indicate the methods that multiple classes need to implement through the interface.

C can understand the interface of the object through the interface, without knowing the corresponding class of the object.

Java does not support multiple inheritance (a class can be a subclass of multiple classes) and uses interfaces to implement its multiple inheritance.

Implements is used in the class declaration to indicate that a class uses an interface, the constants defined in the interface can be used in the class body, and all methods defined in the interface must be implemented. A class can implement multiple interfaces, separated by ",".

These are all the contents of the article "what are the grammatical rules of JAVA?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report