What's the semantical difference between the two statements?

Zaid Khan

I have two (pretty useless) interfaces with test1 extending test

interface test
{
    int a = 8;
    void show();
}

interface test1 extends test
{
    int a = 4;
    void show();
}

I have a class MyClass (again a bit useless) implementing the test1 interface

public class MyClass implements test1
{
    public void show()
    {
       System.out.println(((test)this).a);    // 1
       System.out.println(test.a);            // 2
    }
    public static void main(String ar[])
    {
        new MyClass().show();
    }
}

Out of the code I've provided, I'm interested in knowing what is the semantical difference(if any) between the two statements ordered as 1. and 2. respectively; Because result wise, correct me if I'm wrong they're pretty much the same.

Andrew Tobilko

There is no difference. But it's not a good practice to refer to static members through an instance reference.

Casting this to a parent to access its static field is really misleading.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What's the difference between these two statements in Javascript?

what's the difference between the two statements?

What's the difference between a while loop in one or two statements?

What's the difference between these two statements (R / dplyr)

What is the difference between these two java statements?

What is the difference between these two sql statements(JDBC)?

What is the difference between the following two assignment statements?

What is the difference between these two regular expression statements

Benefit Of Repository and what is difference between two statements

what is the difference between these two statements in R?

What's the difference between '==' and 'in' in if conditional statements?

What is the difference between these if statements?

What is the difference between these two print statements in Perl? And what is the if statement doing?

Is there a semantical difference between <tag /> and <tag></tag> in XML?

Difference between two yield statements

Is there a difference between these two statements in Linq?

Whats the difference between these two statements?

The difference between two count statements

What's the difference between requires and requires transitive statements in Java 9?

What's the difference between requires and requires transitive statements in Java 9?

What's the difference between requires and requires transitive statements in Java 9?

What's the difference between these 2 simply if statements in java

What's the difference between two QHeaderView signals?

What's the difference between these two types of parameters?

What's the difference between these two dd commands?

What's the difference between these two memory allocations?

What's the difference between these two queries?

What's the difference between these two addAction declaration?

What's the difference between these two printer icons?

TOP Ranking

HotTag

Archive