`

class and inheritance

    博客分类:
  • PHP
阅读更多
class and inheritance

class Base:
	def __init__(self):
		self.data = []
	def add(self, x):
		self.data.append(x)
	def addtwice(self, x):
		self.add(x)
		self.add(x)
		

# Child extends Base
class Child(Base):
	def plus(self,a,b):
		return a+b
		
oChild=Child()
oChild.add("str1")
oChild.addtwice("up");
print oChild.data
print oChild.plus(2,3)
print str(type(oChild.data))
print type(oChild.data)


U:\code>python tt.py
['str1', 'up', 'up']
5
<type 'list'>
<type 'list'>
分享到:
评论

相关推荐

    《面向对象程序设计C++》期末考试试卷.pdf

    1. 类与继承(Class and Inheritance) - 在面向对象编程中,类是创建对象的模板,可以封装数据和操作数据的方法。 - 继承是面向对象编程中一个重要的特性,它允许一个类(派生类)继承另一个类(基类)的特性。 ...

    JAVA实验报告,IO编程,JAVA基本语法,接口、抽象类与包,类与继承

    6. **类与继承(Class and Inheritance)**:Java支持单一继承,一个子类只能直接继承一个父类,但可以通过接口实现多重继承的效果。继承使得子类可以继承父类的属性和方法,增强了代码的复用性。例如,`class ...

    精品资料(2021-2022年收藏)面向对象技术Java期末复习试卷五.doc

    2. **类与继承(Class and Inheritance)**: - `Person`类是基础类,包含了`name`属性和构造器,`toString()`方法用于打印对象的基本信息。 - `Student`类继承自`Person`类,并添加了`grade`属性,同时实现了`...

    class_inheritance.zip_系统编程_Visual_C++_

    // base class members (methods and data members) }; class Derived : public Base { public: // derived class members void someMethod() override; }; ``` 在这个例子中,`Derived`类公开地继承自`Base`类...

    javascript-datastructure-and-coding-problems:解决JavaScript编码问题

    5. 类与继承(Class and Inheritance):ES6引入了类的概念,但JavaScript的本质仍是基于原型的继承。理解原型链、构造函数、__proto__和Object.create()等。 6. 模块化(Module):了解CommonJS(Node.js)、AMD...

    Taazaa

    3. **类和继承(Class and Inheritance)**:TypeScript支持面向对象编程的类和继承机制,可以创建具有属性和方法的类,并通过继承实现代码复用。 4. **泛型(Generics)**:泛型允许在定义函数、接口或类时引入一...

    Define inheritance classes Car, Bus, Truck and Motor in the files Car.java, Bus.java,

    The class Bus should include data members that hold the following information: Bus type (should be one of Small, Medium, Large types), number of seats. Define necessary methods in the class Bus.

    hibernate Table per class hierarchy 例子代码

    在Java的持久化框架Hibernate中,"Table per Class Hierarchy"是一种继承映射策略,它在数据库层面将类继承关系转换为单一表的结构。这种策略适用于子类相对较少,且共享很多公共属性的情况,因为它避免了为每个子类...

    Jpaca 帮助文档 Jpcap API EN.CHM

    Class inheritance diagram Direct Subclasses All Known Subinterfaces All Known Implementing Classes Class/interface declaration Class/interface description Nested Class Summary Field Summary ...

    Learning Android: Develop Mobile Apps Using Java and Eclipse(第二版)

    Interfaces and Inheritance Collections Generics Threads Summary Chapter 3 The Stack Stack Overview Linux Native Layer Dalvik Application Framework Applications Summary Chapter 4 Installing and ...

    Objective-C头文件导出工具class-dump

    -I sort classes, categories, and protocols by inheritance (overrides -s) -o &lt;dir&gt; output directory used for -H -r recursively expand frameworks and fixed VM shared libraries -s sort classes and ...

    C 程序设计教学课件:CHAPTER 8 INHERITANCE.ppt

    3. **8.3 Public, Private, and Protected Inheritance** - 公开继承(Public Inheritance)遵循"Is-A"关系,派生类可以被视为基类的一种。私有继承(Private Inheritance)则表达了一种"Has-A"关系,基类的公有和...

    Java Methods-Class Hierarchies and Interfaces.ppt

    首先,让我们来看看继承(Inheritance)。继承是对象间“IS-A”关系的体现,即子类对象IS-A(是)父类对象。通过继承,子类可以获取父类的属性和方法,这样便可以在不重复编写相同代码的情况下扩展功能。例如,`...

    Code Visualizer 4.57

    • Show each class and struct's inheritance, reference and use relation. • Show total class inheritance, reference and use relation. • Show whole project's statistics such as class count, function ...

    ExceptionalCpp_47EngineeringPuzzlesProgrammingProblemsSol.chm

    Robust class design and inheritance Compiler firewalls and the Pimpl Idiom Name lookup, namespaces, and the Interface Principle Memory management issues and techniques Traps, pitfalls, and anti-...

    PHP Objects, Patterns, and Practice(Apress,2016)

    It introduces key topics including class declaration, inheritance, reflection and much more. The next section is devoted to design patterns. It explains the principles that make patterns powerful. ...

    ModelMaker.Code.Explorer.v8.0.0.1877.part2

    As a Class Browser it shows classes (inheritance) and members (fields, methods, properties) in two filtered views, similar to the windows explorer. On the left the Explorer docked in the IDE editor. ...

    ModelMaker.Code.Explorer.v8.0.0.1877.part1

    As a Class Browser it shows classes (inheritance) and members (fields, methods, properties) in two filtered views, similar to the windows explorer. On the left the Explorer docked in the IDE editor. ...

Global site tag (gtag.js) - Google Analytics