类构造函数继承 [英] Class constructor inheritance
问题描述
我发现了一个奇怪的情况,可能是没有做到的。
A级{
函数A(){
//第1课的正常构造函数
}
函数B(){
//通用方法
}
}
B级扩展A {
//此类将继承A :: B作为构造函数
}
I found an odd situation that probably isn''t doing what is intended.
class A {
function A() {
// normal constructor for class1
}
function B() {
// a general purpose method
}
}
class B extends A {
// this class will inherit A::B as a constructor
}
推荐答案
tc ***** @ savageResearch.com (Tim Cadell)在留言中写道:< db ****************** ********@posting.google。 com> ...
tc*****@savageResearch.com (Tim Cadell) wrote in message news:<db**************************@posting.google. com>...
我发现了一个奇怪的情况,可能没有做到的意思。
A类{
函数A(){
// class1的正常构造函数
}
函数B(){
//通用方法
}
} > B /类扩展A {
//这个类将继承A :: B作为构造函数
}
I found an odd situation that probably isn''t doing what is intended.
class A {
function A() {
// normal constructor for class1
}
function B() {
// a general purpose method
}
}
class B extends A {
// this class will inherit A::B as a constructor
}
我'我不确定我明白你在说什么。如果我理解你,
你说B级拿起A级的构造函数。为什么那个
是奇数?这就是它在Java中的工作方式,我猜,大多数OOP
语言。构造函数各自按类
层次结构的顺序执行,从顶部开始并向下运行到子类。
或者我是否误解了你?
I''m not sure I understand what you are saying. If I understood you,
you are saying class B picks up class A''s constructor. Why would that
be odd? That is how it works in Java, and, I would guess, most OOP
languages. The constructors each execute in the order of the class
hierarchy, starting at the top and working down to the subclass.
Or did I misunderstand you?
嗨Tim,
我发现了一个奇怪的情况,可能是没有做到的。
类一个{
函数A(){
//正常的构造函数,用于class1
}
函数B(){
//一个通用的方法
}
}
B类扩展A {
//这个类将继承A :: B作为构造函数
}
I found an odd situation that probably isn''t doing what is intended.
class A {
function A() {
// normal constructor for class1
}
function B() {
// a general purpose method
}
}
class B extends A {
// this class will inherit A::B as a constructor
}
将导致构造的继承,导致
你的B类没有定义构造函数。
如果你想改变它,你必须覆盖
继承了自己版本的构造函数....
就像在C ++中一样?有什么奇怪的?
亲切的问候。
Karl Heinz
-
Dipl .Ing。(FH)Karl Heinz Marbaise | www.marbaise.org
Jabba Dabba Dooh ;-) | ICQ#135949029
The inheritance of the construct will result, cause
your class B has not defined a Constructor.
If you like to change this you have to override the
inherited construcotr with your own version....
That like in C++ ? What is odd on that?
Kind Regards.
Karl Heinz
--
Dipl.Ing.(FH) Karl Heinz Marbaise | www.marbaise.org
Jabba Dabba Dooh ;-) | ICQ# 135949029
Karl Heinz Marbaise< kh ******** @ gmx.de>在消息新闻中写道:< c4 ************* @ ID-68093.news.uni-berlin.de> ...
Karl Heinz Marbaise <kh********@gmx.de> wrote in message news:<c4*************@ID-68093.news.uni-berlin.de>...
嗨Tim,
我发现了一个奇怪的情况,可能不是在做什么。
A类{
函数A()//正常构造函数for class1
}
功能B(){
//通用方法
}
B类extends A {
//这个类将继承A :: B作为构造函数
}
I found an odd situation that probably isn''t doing what is intended.
class A {
function A() {
// normal constructor for class1
}
function B() {
// a general purpose method
}
}
class B extends A {
// this class will inherit A::B as a constructor
}
将导致构造的继承,导致你的B类有没有定义构造函数。
如果你想改变它,你必须用你自己的版本覆盖
继承的construcotr ....
在C ++中是这样的?有什么奇怪的?
The inheritance of the construct will result, cause
your class B has not defined a Constructor.
If you like to change this you have to override the
inherited construcotr with your own version....
That like in C++ ? What is odd on that?
但即使他在B类中有一个构造函数,类中的构造函数
A仍然作为构造的一部分执行B级,是吗?
But even if he has a constructor in class B, the constructor in class
A still executes as part of the construction of class B, yes?
这篇关于类构造函数继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!