implementation, encapsulation characteristics.In Messagebodyservice, for example, the initial init () method is called by different implementations, but generate () is different, such as:650) this.width=650; "src=" Http://www.zhangsr.cn/resources/img/blog/attachment/201410/1_20141009105427.jpg "alt=" 1_20141009105427.jpg "/>The abstract implementation of Absmessagebodyservice is as follows:Public abstract class Absmessagebodyservice implements Messag
):#Inherit Studen - def __init__(Self,name,age,clas,score):#Refactoring Construction Method the #studen.__init__ (Self,name,age,clas) #先继承, re-construct -Super (Clas_one,self).__init__(Name,age,clas)#New Class -Self.score=score#adding new Object Members - defTalk (self):#overriding Method + Print('is new talk,%s'%self.name) - defScore_info (self):#new method of adding subclasses + Print(Self.score,'points') A atP=clas_one ('students a', 36,'Three shifts a yea
Polymorphism (Polymoph) refers to the actual type of the object being referenced, "during execution, not during compilation." , its corresponding method is called according to its actual type.Polymorphism is also called dynamic binding, also called late binding.There are three necessary conditions for polymorphic existence:
To have inheritance
To have a rewrite
Parent class reference to child class object
Object-oriented three major feat
The three main characteristics of the aspect direction: encapsulation, inheritance, and Polymorphism:
When we first define a class, we actually extract the common attributes and behaviors of a class of things to form a physical model (Template). This method of research is called abstraction.
I. EncapsulationEncapsulation is to encapsulate the extracted data and the operations on the data, and the data is
Name{get {return _name;}set {value = _name;}}public string Say ()//Create a new method{Return "La La la" +_name;}Student s = new student ();S.name = "ABCD";String str = S.say ();Console.Write (S.STR); The output is the value returned by this method of say, at this time is the LA-la-abcd;Summary: You can assign a value to private within the constructor, and if you reassign it outside, the value assigned to private within the constructor is overwritten, the output is new, and if it is not assigne
First, Package: internal can encapsulate their own implementation details, so that the information is hidden from other categories of destruction; The division of labor between the various classes is clear, other classes do not need to care about the implementation details, class changes in the details, other classes do not need to make changes;Second, Inherit:Derive new classes from existing classes in order to achieve the purpose of function and attribute extension, make it easy to expand,
class.The notation of inheritance:Class Subclass extends Parent classThis way, the class automatically has some properties and methods defined by the parent class.Inheritance considerations:Subclasses can inherit at most one parent class (direct inheritance)All Java classes are subclasses of the object classPolymorphic:Polymorphism is more complex, in addition to the inheritance can constitute polymorphism, the implementation of the interface can als
can override this method of the parent class in the subclass.Three, polymorphicPolymorphism is the multiple forms of a certain class of thingsPerformance in the program: the parent pointer points to the child class objectCondition: 1) having an inheritance relationship2) Subclass overriding parent class method3) Parent class pointer to child class objectAdvantages: Improved code extensibility, reusabilityNote: If the parent pointer points to a subclass object, you need to call the subclass-spec
Not all object-oriented languages have the concept of classes. The concept of class exists in the traditional oop language
Not all object-oriented languages have the concept of classes. The traditional oop language has the concept of class.
Class: Used to abstract objects. The next definition defines the attributes and capabilities (methods) of certain things ).
Abstract: The process of turning a real or logical world entity into an object of a programming language. It can also be called the
obtained by inheriting the Java.lang.Object class directly or indirectly. Inherited classes are called subclasses, and inherited classes are calledAs the parent class. Subclasses cannot inherit member variables and methods in the parent class that have access rights private. Subclasses can override the parent class's methods and name member variables with the same name as the parent class. But Java does notHolds multiple inheritance, which is the ability of a class to derive from multiple class
Encapsulation | inheritance
Encapsulation is the merging of methods and variables into a class that represents the range that an object can hold to accomplish a certain task and the operations it can perform.
Inheritance is the ability to generate new classes based on methods and member variables of existing classes
Polymorphism is the ability of an object to cha
First, the main content:Interface class: ( Only in the work, writing a specification.)Abstract class:Usefulness: At work, if you prescribe several classes, you must have the same method, if you are abstract class.Packaging:1, put some properties or methods (some useful information) in a space.2, Private member encapsulation: private static variable, private property, Private method feature: +__ double underline before variable, and outside class, subc
difference between overrides (abstract method must override)D, abstract methods can only be in the abstract class, and virtual methods can be written in addition to the sealed class3, the method overrides the condition:A, the method signature must be the sameB, access modifier allowed to be amplifiedC, the return type must be the sameSummary: Three main features of object-oriented:encapsulation: Ensure the integrity and security of the object's own dataInheritance: Establish the relationship be
", [Stu Age]); $ - return 0; -}Because the Studengt class inherits the person class, although the subclass does not explicitly describe the instance variables and methods, the student still has an instance variable of age _age and _age getter and setter
But inheritance has a lot to pay attention to:
If the parent class and child classes are in the same file, the Declaration and implementation of the parent class must precede the subclass.
A new instance variable owned by a
outside the world, if not to access, use the Set method to assign a value, use the Get method to get the valueB. It's not necessary to write.The method name of the C.get and set methods is actually fixed, for example: Private String str;----->GETSTR,SETSTRUse of 4.this KeywordsThis represents a reference to the current objectA.this. PropertiesAccessing the member variable "properties" in the current classSummarize:1> Use this to differentiate member variables when the variable name of the priva
superclass with "," delimited(1) using Super-classClass Filter:def init (self):self.blocked = []def filter (self, sequence):return [x for x in sequence if x not in self.blocked]Class Spamfilter (Filter):def init (self):self.blocked = [' SPAM '](2) See if a class is a subclass of another class, using Issubclass>>> Issubclass (Spamfilter, Filter)Ture>>> Issubclass (Filter, Spamfilter)False(3) If you want to know the base class of a Class (you), you can use its special properties __bases__>>> clas
;c->a->d->b,The lookup order is as follows:Python 3The second lookup order: E Inheritance (c,d)-->c Inheritance (A), D Inheritance (B)-->a and B both inherit (Boos), the lookup order is as follows:Lookup order in Python 3: E->c->a->d->b->bossClass Boos: def F1 (self): print (' Boos ') class A (Boos): def F1 (self): print (' A ') class B (Boos): def F1 (self): print (' B ') class C (A): def F1 (self): print (' C ') class D (B): def-F1 (self): prin
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.