A brief analysis of Java’s three major features: encapsulation, inheritance, and polymorphism
Foreword This blog follows the previous blog as an analysis of Java learning at this stage. The previous blog focused on Java’s OO programming thinking and the difference between object-oriented and process-oriented. This blog focuses on the three major technical features of Java, with job analysis. Three major features of Java Encapsulation In object-oriented programming methods, encapsulation refers to a method of partially packaging the implementation details of an abstract functional interface , the method of hiding. It hides some information of the class inside the class and does not allow external programs to access it. Instead, it implements operations and access to the hidden information through the methods provided by the class. How to implement encapsulation: use access control characters private is accessible in the current class default   ; Accessible within the current package and within the current package protected Accessible within the current class and its derived classes public Public access rights, anyone can access There are also accompanying Also appearing are getter and setter methods. (Due to knowledge reasons, the related package and import will not be explained first) The most commonly used one is private. In inheritance, we also inherit the…
The three major characteristics of the Java language: encapsulation, inheritance, and polymorphism
The Java language has three major features, which are: 1. Encapsulation 2. Inheritance 3. Polymorphism 1. Encapsulation of Java What is encapsulation? Why use encapsulation? Case: To make a call on a mobile phone, you only need to dial the number and do not need to know the internal structure of the mobile phone To play a game, you only need to press buttons and do not need to know the internal code structure of the game The meaning of encapsulation: In order to hide the internal complexity of the object, only simple usage is exposed to the outside world, so as to achieve ease of use. Encapsulate methods and properties into classes, try to hide the details of the class, and only provide access methods to the outside world. Benefits of encapsulation: Improves code reusability, facilitates maintenance and expansion; Definition of encapsulation: Encapsulates properties and some methods into an independent whole, as much as possible It hides the internal details of the current class, improves the reusability of the code, and facilitates maintenance and expansion; Expression form of encapsulation: The code is reflected in -> privatization of attributes, definition of methods, Definition of class 2. Inheritance in Java Inheritance,…
PHP Basics Tutorial 11: Encapsulation, Inheritance, and Polymorphism
Content explained in this section Packaging Inheritance Polymorphism Overloading Rewrite Foreword PHP’s object-oriented approach is the same as JAVA’s object-oriented approach, and both are divided into three major features: encapsulation, inheritance, and polymorphism. These three features optimize object-oriented in many aspects. These three characteristics are also issues that need to be considered when developing object-oriented. Encapsulation What is encapsulation in object-oriented terms? Encapsulation: Encapsulate the abstracted data and operations on the data together. The data is protected internally. Other parts of the program can only operate on the data through authorized operations (member methods). Abstraction is mentioned above, which is to extract the common attributes and behaviors (methods) of a class of things to form a template (class). This method of studying problems is called abstraction. Just like our bank account, no matter whose account it is, it includes the account number and password, and there are also some common methods for withdrawing money, depositing money, and checking the balance. Our idea of using encapsulation is: account_no = $account_no; $this->pwd = $pwd; $this->balance = $balance; } //deposit public function deposit($amount, $pwd){ if($pwd == $this->pwd){ echo ' Deposit successful'; $this->balance += $amount; }else{ echo 'Password is incorrect'; } } //Withdraw money…
(Advanced) Learn the three major features of PHP object-oriented (encapsulation, inheritance, polymorphism)
The following is the text of the article: 1. Encapsulation Encapsulation is to encapsulate the extracted data and the operations on the data together. The data is protected internally, and only authorized operations (methods) in other parts of the program can operate on the data. php provides three access control modifiers public means global, and can be accessed inside this class, outside the class, and subclasses protected means protected , only this class or subclass can access private means private, and can only be accessed within this class The above three modifiers can modify both methods and attributes (variables ), if the method does not have access modifiers, it defaults to public. Member attributes must specify access modifiers. There is also this way of writing var $name in PHP4, which means public attributes. This way of writing is not recommended. Example: name=$name; $this->age=$age; $this->salary=$salary; } public function showinfo(){ //This means that all three modifiers can be used inside this class echo $this->name.”||”.$this->age.”||”.$this->salary; } } $p1=new Person('Zhang San',20,3000); //This is outside the class, so if you use the following method to access age and salary, an error will be reported // echo $p1->age; echo$p1->salary; ?> So what should I do if…
Learn the three major characteristics of PHP object-oriented (fully understand abstraction, encapsulation, inheritance, polymorphism)_PHP tutorial
The three major characteristics of object-oriented objects: encapsulation, inheritance, and polymorphism. First, let’s briefly understand abstraction:When we defined a class earlier, we actually extracted the common attributes and behaviors of a class of things. , forming a physical model (template), this method of studying problems is called abstraction1. EncapsulationEncapsulation is to encapsulate the extracted data and operations on the data. The data is protected internally, and other parts of the program only have authorized operations. (Method) to operate on data. PHP provides three access control modifierspublic means global, accessible within this class, outside the class, and subclassesprotected means protected, only this class or subclasses can accessprivate means private and can only be accessed within this classThe above three modifiers can modify both methods and properties (variables). If the method does not have access modifiers, it defaults to public. Member properties must specify access modifiers. , there is also this way of writing var $name in PHP4, which means public attributes. This way of writing is not recommendedExample: The code is as follows: <?php class Person{ public $name; protected $age; private $salary; function __construct($name,$age,$salary){ $this->name=$name; $this->age=$age; $this->salary=$salary; } public function showinfo(){ //This means that all three modifiers can be This class…
PHP functions, classes and objects, as well as class encapsulation, inheritance, class static methods, static attributes, PHP static_PHP tutorial
php functions, classes and objects, as well as class encapsulation, inheritance, class static methods, static properties, php static 1. Function PHP built-in functions can be used directly, if no php extension is installed Custom function //Function function function name function dump($var = null){ //Expenditure default parameter value echo ‘’; var_dump($var); } 2. Class and object (new Obj) <?php //Define a person’s class, which is not an object yet class Person { //Private properties private $eye = ‘Big Eyes’; private $mouth = ‘small mouth’; private $leg = ‘Long legs’; //Call it yourself when constructing the new object public function __construct() { echo __CLASS__; } public function run() { echo $this->leg; } //Learning will use legs (walking), eyes (reading), mouth (reading) public function study() { echo $this->leg, $this->eye, $this->mouth; } } //After using class new, it becomes an object $person = new Person(); //Output Person $person -> run(); //Output Long Legs $person -> study(); //Output Long legs, big eyes, small lips 3. Class encapsulation (public, protected, private) and inheritance (extends) //Class inheritance class A { public function help() { echo __METHOD__; } //Declare an eating method private private function eat() { echo __METHOD__; } } //Subclasses can inherit all public…
PHP functions, classes and objects, as well as class encapsulation, inheritance, class static methods, static attributes – PHP tutorial
PHP functions, classes and objects, as well as class encapsulation, inheritance, class static methods, static properties 1. Function PHP built-in functions can be used directly, if there is no PHP extension installed Custom function //Function function function name function dump($var = null) { //Expenditure default parameter value echo ”; var_dump($var); } 2. Class (class) and object (new Obj) <? php //Define a human class, Not an object yet class Person{ //Private properties private $eye = ‘Big Eyes’; private $mouth = ‘small mouth’ ; private $leg = ‘Long legs’; //Customized call when constructing the new object public function __construct() { echo __CLASS__; } public function run() { echo $this->leg; } //Learning uses legs (walking), eyes (reading), and mouth (reading) ) public function study( ) { echo $this->leg, $this->eye, $this->mouth; } }//After using class new, it becomes an object$person = new Person(); //Output Person$person -> run(); / /Output long legs$person -> study(); //Output long legs, big eyes, small lips 3. Class encapsulation (public, protected, private) and inheritance (extends) //Class inheritanceclass A{ public function help() { echo __METHOD__; } //Declare an eating method private private function eat() { echo __METHOD__; }}//Subclasses can inherit all public methods and properties, as well as…
Learn the three major characteristics of PHP object-oriented (fully understand abstraction, encapsulation, inheritance, polymorphism)_php skills
The three major characteristics of object-oriented objects: encapsulation, inheritance, and polymorphism. First, let’s briefly understand abstraction:When we defined a class earlier, we actually extracted the common attributes and behaviors of a class of things. , forming a physical model (template), this method of studying problems is called abstraction 1. EncapsulationEncapsulation is to encapsulate the extracted data and operations on the data. The data is protected internally, and other parts of the program only have authorized operations (methods). ) to operate on the data. PHP provides three access control modifierspublic means global, accessible within this class, outside the class, and subclassesprotected means protected, only this class or subclasses can accessprivate means private and can only be accessed within this classThe above three modifiers can modify both methods and properties (variables). If the method does not have access modifiers, it defaults to public. Member properties must specify access modifiers. , there is also this way of writing var $name in PHP4, which means public attributes. This way of writing is not recommendedExample: The code is as follows: <?php class Person{ public $name; protected $age; private $salary; function __construct($name,$age,$salary){ $this->name=$name; $this->age=$age; $this- >salary=$salary; } public function showinfo(){ //This means that all three modifiers…
Learn the three major characteristics of PHP object-oriented (fully understand abstraction, encapsulation, inheritance, polymorphism)_PHP
The three characteristics of object-oriented: encapsulation, inheritance, and polymorphism First, let’s briefly understand the abstraction:When we defined a class earlier, we actually extracted the common attributes and behaviors of a class of things , forming a physical model (template), this method of researching problems is called abstraction1. EncapsulationEncapsulation is to encapsulate the extracted data and the operation on the data together, the data is protected inside, and other parts of the program only have authorized operations (method) to operate on the data. php provides three access control modifierspublic means global, inside this class, outside the class, and subclasses can accessprotected means protected, only this class or subclasses can accessprivate means private, only accessible inside this class , there is also this way of writing var $name in PHP4, which means public attributes, and this way of writing is not recommended Example: The code is as follows: <?php class Person { public $name; protected $age; private $salary; function __construct($name,$age,$salary){ $this->name=$name; $this->age=$age; $this->salary=$salary; } public function showinfo(){ //This means that all three modifiers are available Inside this class use echo $this->name.”||”.$this->age.”||”.$this->salary; } } $p1 =new Person(‘Zhang San’,20,3000); //This is outside the class, so if you use the following method to access age…
Detailed explanation of advanced features of PHP object-oriented programming (interface, inheritance, abstract class, destruction, cloning, etc.)
This article describes the advanced features of PHP object-oriented programming with examples. Share it with everyone for your reference, as follows: Static attributes Output: 0 hello Comments: Static properties and methods can be called directly through the class. SELF Output: hello (1) hello (2) hello (3) Comment: self points to the current class, this points to the current object. self can call the static properties and methods of the current class. this points to the current object. self can call the static properties and methods of the current class. this can call the normal properties and methods of the current class. Constant attribute Output: 0 Comments: Constants can only use uppercase letters, and can be called directly through the class. Interface price; } //… } $product = new ShopProduct(); ?> If the getPrice method is not implemented, an error will be reported. Fatal error: Class ShopProduct contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Chargeable::getPrice) Inheriting classes and interfaces Abstract class Look at a piece of code first Output: Document Object ( ) Static methods group = static::getGroup();//static static class } public static function create() { return new static(); } static function getGroup()…