Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Sat Jul 06, 2019 10:33 am
by BaxLi007
As a completion - it is possible to make both methods static in interface and in FooBase...
Or to switch make bar static in Interface and non-static in FooBase

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Sat Jul 06, 2019 11:55 am
by admin
What happened when you tried it out?

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Sat Jul 06, 2019 12:09 pm
by BaxLi007
all is compiling successfully ...
// case 1
interface Bar {
static void bar(){};
}
abstract class FooBase {
static public void bar(){} ;
}
public class Test extends FooBase implements Bar {
}

// case 2
interface Bar {
static void bar(){};
}
abstract class FooBase {
abstract public void bar();
}
public class Test extends FooBase implements Bar {
public void bar(){};
}

// case 3
interface Bar {
static void bar(){};
}
abstract class FooBase {
public void bar(){};
}
public class Test extends FooBase implements Bar {
}

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Sat Jul 06, 2019 12:16 pm
by admin
OK, very good. So, what is your question?

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Sat Jul 06, 2019 12:33 pm
by BaxLi007
Excuse me, I'm wasn't explicit enough. It wasn't a question - it is a completion of the possible correct answers ...

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Sat Jul 06, 2019 8:12 pm
by admin
ok :thumbup:

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Mon Sep 02, 2019 4:49 pm
by rcarinha@hotmail.com
The code will compile correctly, if:

Make the bar method in Bar interface default like this - default void bar() { }

Shouldn't this be the correct answer?

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Mon Sep 02, 2019 11:10 pm
by admin
What happened when you tried it out?

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Tue Sep 03, 2019 1:41 pm
by rcarinha@hotmail.com
It happened exactly what I stated above... it compiled correctly:

interface Bar{
default void bar(){};
}

abstract class FooBase{
public static void bar(){
System.out.println("In static bar");
}

}

public class Foo extends FooBase implements Bar{

}

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Tue Sep 03, 2019 8:57 pm
by admin
Are you sure? The code that you have posted doesn't compile.

Re: About Question enthuware.ocajp.i.v8.2.1493 :

Posted: Wed Sep 04, 2019 2:42 pm
by rcarinha@hotmail.com
You are correct. It was an issue with IntelliJ. It does not show the compilation error, until I build or execute the code(adding a main method).
My bad! Thanks for the reply!