Error: The superclass, ‘Animal‘, has no unnamed constructor that takes no arguments.
Error: The superclass, ‘Animal’, has no unnamed constructor that takes no arguments.
错误:超类“Animal”没有不带参数的未命名构造函数。
问题描述:
因为构造函数没法继承
继承时候报错,提示父类里面的构造函数是由参数的,需要在子类里面也写上构造函数,将父类的构造函数传参
class Animal {String name;int age;Animal(this.name, this.age);void printInfo() {print('$name is $age years old');}
}//通过extends关键词继承Animal类
class Cat extends Animal {}void main(List<String> args) {Cat cat = new Cat();print( cat.name);
}
解决方案:
super关键词
Try declaring a zero argument constructor in ‘Animal’, or declaring a constructor in Cat that explicitly invokes a constructor in ‘Animal’.dart(no_default_super_constructor)
尝试在“Animal”中声明零参数构造函数,或在Cat中声明显式调用“Animal”中构造函数的构造函数。dart(无默认超级构造函数)
class Animal {String name;int age;Animal(this.name, this.age);void printInfo() {print('$name is $age years old');}
}//通过extends关键词继承Animal类
class Cat extends Animal {Cat(String name, int age) : super(name, age);}void main(List<String> args) {Cat cat = new Cat("Huahua",3);print( cat.name);
}
Error: The superclass, ‘Animal‘, has no unnamed constructor that takes no arguments.相关推荐
- C# error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments的解决方案
出现这种错误的原因时,没有在子类的构造函数中指出仅有带参构造函数的父类的构造参数. 具体来讲就是: 当子类要重用父类的构造函数时, C# 语法通常会在子类构造函数后面调用 : base( para_t ...
- TypeError: Animal() takes no arguments
问题参考 Python中报错提示:TypeError: Student() takes no arguments 问题背景 在联系python经典面试题的时候,做到了解引用计数机制时,创建类报错 附上 ...
- error C2679: binary ‘<<‘ : no operator defined which takes a right-hand operand of type ‘class s
c++ 报错error C2679: binary '<<' : no operator defined which takes a right-hand operand of type ...
- C# does not contain a constructor that takes no parameter
C# 中子类要重用父类的构造函数时, 一般会在子类构造函数后面调用 : base(paratype, para). 如果父类有一个參数个数为1的构造函数, 没有 0 參构造函数. 子类想要重用这个构造 ...
- 王权富贵:TypeError: this constructor takes no arguments
这里的问题是,对应类的初始化出错了 我这边的错误是:初始化函数是 __init__ 我写的是 __int__
- 直接使用汇编编写 .NET Standard 库
前言 Common Language Runtime(CLR)是一个很强大的运行时,它接收 Common Intermediate Language(CIL) 的输入并最终产生机器代码并执行.CIL ...
- C++ 下面的AIDL
转自https://android.googlesource.com/platform/system/tools/aidl/+/brillo-m10-dev/docs/aidl-cpp.md. Bac ...
- [转]XNA 3.1 转换到 XNA4.0 的备忘录
XNA 3.1 转换到 XNA4.0 的备忘录 xna3.1与4.0的区别不小,但也不是很大,在转换一些项目时候下面的tip能给些帮助.原文地址是:http://blogs.msdn.com/b/sh ...
- XNA 3.1 转换到 XNA4.0 的备忘录
本文原创版权归 博客园 Meta.Grfx 所有,转载请详细标明原创作者及出处,以示尊重! 作者:Meta.Grfx 原文:http://www.cnblogs.com/Baesky/archive/ ...
最新文章
- PowerPC中断系统简介(一)
- Git 常用命令集锦 1
- Django笔记01-基础:一个完美主义的web框架
- UEditor编辑器第一次赋值失败的解决方法
- LeetCode 1268. 搜索推荐系统(Trie树/multiset)
- 如何在服务器上使用宝塔面板?
- List、Map、Set三个接口,存取元素时,各有什么特点
- .tar.bz2 解压出错问题解决方案
- my eclipse 破解通用步骤
- 【RDKit】Python化学包RDkit的教程
- 能查阅国外文献的8个论文网站(最新整理)
- 北京环球度假区宣布首批21家旅游渠道官方授权合作伙伴
- DyingGasp电路(掉电检测电路)设计
- vue rsa加密 php解密,Vue项目中的RSA加解密
- 奋斗的青春,无悔的时光
- Learning Pose Grammar to Encode Human Body Configuration for 3D Pose Estimation论文阅读笔记
- 项目经理的岗位职责和要求
- git版本回退命令_刘先生
- JAVA如何利用迅雷接口解析磁力,关于神秘代码(磁力链接)如何正确使用
- python图片水印
热门文章
- mysql2000名称_[转载]编写SQL语句查询出每个各科班分数最高的同学的名字,班级名称,课程名称,分数...
- 基于分段平面性的单目深度估计 P3Depth: Monocular Depth Estimation with a Piecewise Planarity Prior
- std::map使用std::piecewise_construct std::forward_as_tuple
- 机器人仿真平台——RobotHw
- boostbuck电路
- 数据自动备份解决方案
- 完整版! 大一新手C语言数据结构实现简单贪吃蛇游戏
- 14.学习Camera之——camera基本知识
- js实现中国标准时间转换YYYY-MM-DDD 00:00:00形式
- 【Java】读取单颗北斗卫星导航星历文件进行卫星位置计算(RENIX3.04)