Suppose I have two interfaces I and J that is implemented by Test class. Now I need one object of class Test that is referenced by I and J both interfaces. I can do it by singleton design pattern. But the problem is sometime I won't need a single object in the program. So there is also another approach that I have known. I i = new Test();i.doSomeThing();J j = (J) i;j.print();My question, is there any better way to do this ? ...UPDATE...public interface I {void doSomeThing();}public interface J {void print();}public class Test implements I, J{private int a;@Overridepublic void doSomeThing() {    a += 10;}@Overridepublic void print() {    System.out.println(this.a);}}...UPDATE...public class Main {    public static void main(String[] args) {    I i = new Test();    foo(i);    J j = (J) i;    ffoo(j);}/*** This method has business with only the doSomething method that  * implement the Test class. This method has not nothing with the print* method that is in the Test class. So it would be well that only pass * the I interface to the foo method. */public static void foo(I i) {    i.doSomeThing();}public static void ffoo(J j) {    j.print();}}
How to reference one object with two interfaces?
object oriented design;coding standards
Why not this?public class Main {    public static void main(String[] args) {        Test i = new Test();        foo(i);        ffoo(i);    }    public static void foo(I i) {        i.doSomeThing();    }    public static void ffoo(J j) {        j.print();    }}It looks like, in the context of your code, you need a Test instance.You don't need to cast your Test to I or J.  Let polymorphism do its magic for you.