In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you what are the differences between php and java object-oriented, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Differences: 1. The class keyword of php cannot have modifiers other than abstract and final, while Java can. 2. The class name after the new keyword of php can be a variable of string type, but java cannot. 3. When accessing the parent object, php uses parent and java uses super.
Operating environment of this tutorial: windows7 system, PHP7.1&&java8 version, DELL G3 computer
Incomplete object-oriented comparison between PHP and Java
PHP is a weakly typed language, which can be programmed in either a process-oriented way or an object-oriented way. Java is a strongly typed language, purely object-oriented. The two languages have some similarities in object-oriented. With the learning experience of Java, it is easy to learn PHP. Just looking at these keywords (class, extends, interface, implements, final, public, protected, private, static) has a very familiar feeling.
A brief summary of the similarities and differences in several aspects, I am not an academic school, only practical, if there are mistakes, welcome to correct.
Comparison 1: declaration of class and interface, class inheritance, declaration of interface implementation, comparison of the same point, different point of class declaration all use the class keyword, which can be modified with abstract and final, the meaning of these two modifiers is the same. The class keyword of php cannot have modifiers other than abstract and final, and the class keyword of Java can have public, proctected, private modifiers. A file of Java can only have one public class interface declaration with interface keyword same as the above class inheritance with extends keyword, single inheritance without interface inheritance with extends keyword without interface implementation with implements keyword, can realize classless instantiation of multiple interfaces with new keyword, which is a reference to the returned object, object assignment is also a reference to the new keyword assigned to php, and the class name after the new keyword of the assignment php can be a variable of string type, and java cannot access the parent object.
Php uses the parent keyword, java uses the super keyword to compare 2: access modifiers are compared with access methods at the same point, different point modifier keywords are public, protected, private without modifiers public: both inside and outside the class can be accessed, protected: the interior of the class and subclasses can be accessed, private: only the interior of the class can access the access control of php. The default modifier is public. Java defaults to private instance members and access methods of instance methods No php must use $this- >, java can also omit comparison 3 with this.,: class members and class methods compare point same point different point keyword static no scope all instances of this class have no access method class name: variable or function name, no instantiation can access no comparison 4: class constant comparison point same point different point keyword constjava usually uses final Php cannot use final scope all instances of this class have no access method class name: variable or function name, can be accessed without instantiation 5: abstract methods and abstract classes
Basically the same, abstract methods and abstract classes are modified with the abstract keyword, at least one abstract method class is called abstract class, abstract class can not be instantiated, if the subclass can be instantiated, all abstract methods of the parent class must be implemented.
Comparison 6: rewrite / overwrite / overload
The subclass method is exactly the same as the parent method signature, which is called rewriting / overwriting, and the parent method is not visible in the subclass. Because Java is a strongly typed language, it has an overloading mechanism (same method name, different signatures, and determines which method is called according to the actual parameter type and number when calling). PHP is a weak type, without such overloading, but with the overload of dynamically creating class properties and methods, which is achieved through magic methods (_ _ get, _ _ set, _ _ unset, _ _ isset, _ _ callStatic).
The above is all the content of the article "what is the difference between php and java object-oriented". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.