多字段继承,为避免混淆,simple name与qualified name的使用

package java20180129_1;

interface Frob {
float v=2.0f;
}
class SuperTest{
int v=3;
}
class Demo extends SuperTest implements Frob{
public static void main(String[] args) {
new Demo().printV();
} /**
* 多继承字段
* 不能直接写v,要么写成super.v,要么写成Frob.v
*/
void printV(){
// System.out.println(v);
System.out.println((Frob.v+super.v)/2);
}
}
package java20180129_1;
interface Color{
int RED=0,GREEN=1,BLUE=2;
}
interface TrafficLight{
int RED=0,YELLOW=1,GREEN=2;
}
class Demo implements Color, TrafficLight {
public static void main(String[] args) {
// System.out.println(GREEN);
// System.out.println(RED); System.out.println(TrafficLight.GREEN);
System.out.println(Color.RED);
}
}

下面的Red不会产生混淆

package java20180129_1;

interface Colorable {
int RED = 0xff0000, GREEN = 0x00ff00, BLUE = 0x0000ff;
} interface Paintable extends Colorable {
int MATTE = 0, GLOSSY = 1;
} class Point {
int x, y;
} class ColoredPoint extends Point implements Colorable {
} class PaintedPoint extends ColoredPoint implements Paintable {
int p = RED;
}

java_字段声明的更多相关文章

  1. SQL 数据库加字段声明

    ALTER TABLE dbo.C_TrainPlan ADD MailCost DATETIME EXECUTE sp_addextendedproperty N'MS_Description', ...

  2. C#字段声明部分如何调用该类中的方法进行初始化?

    问题描述: 有时,功能需求,需要在初始化字段时,需要视不同情况赋予不同字段值. 解决办法: 将方法设为static即可. e.g. public string str = SetStr(); publ ...

  3. java_字段初始化的规律、静态方法中访问类的实例成员、查询创建对象的个数

    字段初始化规律: 当执行如下代码时 class InitializeBlockClass{ public int field=100; { field=200; } public Initialize ...

  4. [.net 面向对象编程基础] (10) 类的成员(字段、属性、方法)

    [.net 面向对象编程基础] (10) 类的成员(字段.属性.方法) 前面定义的Person的类,里面的成员包括:字段.属性.方法.事件等,此外,前面说的嵌套类也是类的成员. a.类的成员为分:静态 ...

  5. SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int

    --SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int --关键说明:--1.从系统表syscolumns中的查询所有xtype='48'的记录得到类型为[tinyint]的字段- ...

  6. C# 之 静态字段初始化

          当一个字段声明中含有 static 修饰符时,由该声明引入的字段为静态字段(静态变量).当不存在 static 修饰符时,由该声明引入的字段为实例字段(实例变量).       静态字段不 ...

  7. C#常量字段

    const 常量字段使用方法 using System;using System.Collections.Generic;using System.Linq;using System.Text;usi ...

  8. C# 类属性封装、字段的详解

    今日敲代码时,突然感觉对类的属性封装.字段有点犯迷糊了..连基础的都不知道了,那敲的代码怎么能严谨高效的.果断拿起各种高级编程.大全啥的翻起来~~这不再把自己的理解写下来(定义都是直接抄书的),献给同 ...

  9. Programming C#.Classes and Objects.只读字段

    只读字段 当字段声明中含有 readonly 修饰符时,该声明所引入的字段为只读字段.给只读字段的直接赋值只能作为声明的组成部分出现,或在同一类中的实例构造函数或静态构造函数中出现.(在这些上下文中, ...

随机推荐

  1. Codeforces 40 E. Number Table

    题目链接:http://codeforces.com/problemset/problem/40/E 妙啊... 因为已经确定的格子数目严格小于了$max(n,m)$,所以至少有一行或者一列是空着的, ...

  2. webpack引入eslint详解

  3. MDK编译过程

    原博文:https://blog.csdn.net/qq_33894122/article/details/83994564

  4. 『Python CoolBook』数据结构和算法_多变量赋值&“*”的两种用法

    多变量赋值 a = [1,2,(3,4)] b,c,d = a print(b,c,d) b,c,(d,e) = a print(b,c,d,e) 1 2 (3, 4) 1 2 3 4 a = &qu ...

  5. Java-Mail邮件开发

    Email的历史比Web还要久远,直到现在,Email也是互联网上应用非常广泛的服务. 几乎所有的编程语言都支持发送和接收电子邮件,但是,先等等,在我们开始编写代码之前,有必要搞清楚电子邮件是如何在互 ...

  6. Guava:好用的java类库 学习小记

    基础功能 google guava中定义的String操作 在google guava中为字符串操作提供了很大的便利,有老牌的判断字符串是否为空字符串或者为null,用指定字符填充字符串,以及拆分合并 ...

  7. angularjs 下滑线滑动

    css: .detail_row { width: 410px; height: 34px; clear: both; border-bottom: 1px solid #eaeeef; font-s ...

  8. python-模块2

    from collections import namedtuple # # 类 # p = namedtuple("Point", ["x", "y ...

  9. asp.net core mvc HTTP Error 502.5 - Process Failure

    HTTP Error 502.5 - Process Failure Common causes of this issue: The application process failed to st ...

  10. E: Sub-process /usr/bin/dpkg returned an error code (1)错误解决

    在用apt-get安装软件时出现了类似于install-info: No dir file specified; try --help for more information.dpkg:处理 get ...