Based on example you provided can we say that the static variable of an interface is not inherited ?
Just like static methods.
[HD Pg 251, Sec. 9.2.5 - inheritance-of-multiple-versions-of-a-variable]
Moderator: admin
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 251, Sec. 9.2.5 - inheritance-of-multiple-versions-of-a-variable]
First, check out what is meant by inheritance as explained in 9.1.4 "Inheritance of instance members vs static members".
Second, the situation with fields of an interface is explained under section 9.2.5 under paragraph that you mentioned. It says, "Fields of an interface are inherited by a sub class and therefore Process does get two versions of SIZE variable.".
and then again in 9.2.6 under para titled, "Inheriting multiple variables with same name". It says, "Static fields of an interface are inherited by a sub interface and therefore ReadWritable does get two versions of SIZE variable."
Second, the situation with fields of an interface is explained under section 9.2.5 under paragraph that you mentioned. It says, "Fields of an interface are inherited by a sub class and therefore Process does get two versions of SIZE variable.".
and then again in 9.2.6 under para titled, "Inheriting multiple variables with same name". It says, "Static fields of an interface are inherited by a sub interface and therefore ReadWritable does get two versions of SIZE variable."
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: [HD Pg 251, Sec. 9.2.5 - inheritance-of-multiple-versions-of-a-variable]
I think I understood the concept with this program.
You can even delete this question.
You can even delete this question.
Code: Select all
interface Task{
int SIZE = 10;
default void doIt(){
System.out.println("Doing Task");
}
static void wontWork() {};
}
interface Activity{
//long SIZE = 20;
//void doIt();
}
public class TestClass implements Task, Activity{
public static void main(String[] args){
TestClass p = new TestClass();
//p.doIt();
long l = p.SIZE; //inherited
long l1 = SIZE; //inherited
p.wontWork(); //cannot find symbol
Task.wontWork(); //works
}
}
Who is online
Users browsing this forum: Bing [Bot] and 22 guests