问题是这样的:一个父类中有一个方法,一个接口中有一个与父类方法重名的方法,现在子类中要同时继承父类和实现接口,那么应该怎么区分子类的方法是重写的父类的还是实现的接口的。基类代码:public class Father { public Father() { System.out.pri...
分类:
编程语言 时间:
2015-08-04 13:13:43
阅读次数:
197
现在的现象是子类继承父类。然后重写了父类的一个方法,父类的构造函数中调用了父类的这个方法,那么当子类实例化连带父类实例化时调用的就是子类重写的方法。代码:父类:public class Father { public Father() { System.out.println("基类构...
分类:
编程语言 时间:
2015-08-04 12:58:36
阅读次数:
92
和上一道题一样,可以用DAG上的动态规划来做,也可以建立一个源点,用spfa来做 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 const ...
分类:
其他好文 时间:
2015-08-03 20:54:48
阅读次数:
97
参考代码
#include
#include
using namespace std;
class father {
int id;
protected:
int tt;
public:
father():id(3){}
void print() {printf("this is father public function %d\n",id);}
void changeId() ...
分类:
编程语言 时间:
2015-08-03 19:19:39
阅读次数:
147
1.题意:给n个单词,问是否能按成语接龙的方式将所有的单词串连起来。
2.思路:把单词看成是从首字母到尾字母的有向边(弧)即可。只要该有向图是欧拉图,那么就可以连。否则不可以。写并查集中的Union的时候要注意是a=Find(a);不要再重复犯错了
3.代码:#include
#include
using namespace std;
int father[30];
char s[1005]...
分类:
其他好文 时间:
2015-07-29 19:23:21
阅读次数:
121
其实巨水...然而 不用scanf prinf 根本过不了.....真无聊第一版代码有点问题 效率不高 主要是考虑到这个家族有可能一开始就是个森林 不是从树里分出去的实际上数据点还是一棵树 然后变成的森林 这样的话只要三个数组就可以了alive记录是否活着sons记录每个人的子节点个数father记...
分类:
编程语言 时间:
2015-07-29 06:18:39
阅读次数:
144
Java构造器在初始化的构成中经常会使用到this和super关键词,那么他们到底是特定类的引用还是对象呢?下面我们逐步看清他们的真实面目。
先看例子1——这个this到底是什么类型,又是谁的对象?
package java_zhaohuaxishi;
class Father{
private String name = "父亲";
public Father(){...
分类:
其他好文 时间:
2015-07-28 21:17:02
阅读次数:
278
java 转型问题其实并不复杂,只要记住一句话:父类引用指向子类对象。什么叫父类引用指向子类对象,且听我慢慢道来.从2个名词开始说起:向上转型(upcasting) 、向下转型(downcasting).举个例子:有2个类,Father是父类,Son类继承自Father。Father f1 = ne...
分类:
编程语言 时间:
2015-07-26 05:56:41
阅读次数:
179
答案是,不会。子类优先实现父类的方法,虽然父类的方法和接口的方法长得一模一样。class father{ public void f(){}}interface sameInterface{ public void f();}class son extends father implem...
分类:
编程语言 时间:
2015-07-25 16:46:19
阅读次数:
148
代码:
#include
#include
using namespace std;
int n,m;
int father[1005];
int Find(int a)
{
int r=a;
while(father[a]!=a)
{
a=father[a];
}
father[r]=a;
return a;
}
void ...
分类:
其他好文 时间:
2015-07-24 22:46:06
阅读次数:
208