Doubts in interface

If any data member of an interface ia automatically public, static and final then how we can shadow it in the class which is implementing the interface?
interface iTest {
     public static final int i = 5;
     public void display();
public class TEst implements iTest {
     int i = 10;
     public void display() {
          System.out.println(i);
     public static void main(String a[]) {
          TEst t = new TEst();
          t.display(); //prints 10 , why not 5?
}Thanks for your reply.

- Hiding Member Variables -
Note: it is a good practice to refer to a static member by prefixing it with class name:     public static void main(String a[]) {
          TEst t = new TEst();
          t.display(); // prints 10
          System.out.println(iTest.i); // prints 5
     }

Similar Messages

  • I have doubts in interface

    Hi all,
    I have doubts in interface . You please help me.
    My question was
    i have two interface. and also i have only one method in both interfaces.these method are same name in both interface
    Now i implement these interfaces in my class it's work properly. it doesn't through exceptions.
    But i have changed the return type of methods,
    ie i put int for one
    and void for another one.
    it throws exceptions . duplicate method access.
    how to i solve this problem? did u catch my point?
    please help me Advance in thanks.

    i have two interface. and also i have only one
    y one method in both interfaces.these method are same
    name in both interface
    Now i implement these interfaces in my class it's
    work properly. it doesn't through exceptions.
    But i have changed the return type of methods,
    ie i put int for one
    and void for another one.
    it throws exceptions . duplicate method access.
    how to i solve this problem? did u catch my point?Yes I caught it. The solution: don't do it. Methods differ by name and argument type list. Return values are not looked at.
    Another solution: have the methods take different arguments. Or rename one of them.

  • Clear my  doubt on Interface

    Hi,
    When a class implement an interface,the method of the class should thorugh the same exception or any of its subclass exception or any different exception,as that of the exception declared on the abstarct method of the interface.
    Please any one solve my doubt as early as possible.
    Thanks
    Vish

    Hi,
    When a class implement an interface,the method of
    the class should thorugh the same exception or any of
    its subclass exception or any different exception,as
    that of the exception declared on the abstarct method
    of the interface.
    Is this supposed to be multiple choice?
    The easiest way for you to answer this question is to try it out yourself in code.

  • Doubt about interfaces in "final Runnable closerRunner = new Runnable()"

    Till this date i think that interfaces can not be instantiated because they dont define methods.But one line of code found in a sample program(creating splash screen)creates lots of confusions to me.The line is as follows:
    final Runnable closerRunner = new Runnable()
    An interface is instantiated using "new" operator.How is this possible ?
    Any body help me please.
    The whole program follows:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class SplashWindow3 extends JWindow
    public SplashWindow3(String filename,JFrame f, int waitTime)
    super(f);
    JLabel l = new JLabel(new ImageIcon(filename));
    getContentPane().add(l, BorderLayout.CENTER);
    pack();
    Dimension screenSize =
    Toolkit.getDefaultToolkit().getScreenSize();
    Dimension labelSize = l.getPreferredSize();
    setLocation(screenSize.width/2 - (labelSize.width/2),
    screenSize.height/2 - (labelSize.height/2));
    addMouseListener(new MouseAdapter()
    public void mousePressed(MouseEvent e)
    setVisible(false);
    dispose();
    final int pause = waitTime;
    final Runnable closerRunner = new Runnable()
    public void run()
    setVisible(false);
    dispose();
    Runnable waitRunner = new Runnable()
    public void run()
    try
    Thread.sleep(pause);
    SwingUtilities.invokeAndWait(closerRunner);
    catch(Exception e)
    e.printStackTrace();
    // can catch InvocationTargetException
    // can catch InterruptedException
    setVisible(true);
    Thread splashThread = new Thread(waitRunner, "SplashThread");
    splashThread.start();
    public static void main(String [] a)
              //this.setSize(1000,1000);
              JFrame f=new JFrame();
              f.setSize(300,300);
              SplashWindow3 s=new SplashWindow3("shan.jpg",f,100000);
    }

    That is called an anonymous inner class.
    See JLS 15.9.
    http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.9

  • Hi sdn gems doubt on interface pls help

    my question is i have to do interface between ctts system to sap, in asingle program i have to upload two transactions MSC2 and MB1B with movement 311.
    can anyone pls help by sending code are suggestion.

    HI,
    You can do for any number of transactions.. one after the other...
       prepare BDC data for tcode 1
       call transaction 1.
       prepare bdc dta for tcode 1.
       call transaction 2.
      Thaks
    Mahesh

  • Doubt about interface & abstract

    Hai everybody,
    I am new java technology. I need clear discribtion about interface & abstract.
    Please give some examples and differentiate it.
    i awaiting for your reply
    by
    azhar

    Even Wikipedia has info about this:
    http://en.wikipedia.org/wiki/Interface_%28Java%29
    http://en.wikipedia.org/wiki/Class_%28computer_science
    %29#Abstract_and_concrete_classeswhenever someone asks this question, they don't really want to read about it, they just want someone to tell them the secret rules about when to use an interface and when to use an abstract class. but we're not telling :-)

  • Doubt in interface reference

    Select two correct statements about the code given below?
    class A{}
    class B extends A implements E{} //line 1
    class C extends A{}
    class D extends B{}
    interface E{}
    class Question07 {
    public static void main(String[] args) {
    A a = new D(); //line 2
    C c = new C(); //line 3
    E e = (E)a; //line 4
    B b = e; //line 5
    }Options
    a. The code compiles without error and runs fine
    b. Compilation error on line 1 because interface E is not yet declared (forward-referencing)
    c. Compilation error on line 4 because class A does not implement interface E
    d. The cast on line 4 is mandatory
    e. The cast on line 5 is not mandatory
    the answer is a,d,e three answers ! all answers understood except d option
    how we can make E reference with casting A , and A is not implement E !!!
    help me please
    Message was edited by:
    eaaje
    Message was edited by:
    eaaje

    The type of variable a is A. Since A does not implement E, to assign a to a variable of type E you must cast it.

  • Doubt on interface IFMD006.

    Hi Friends,
    I was asked to make changes to interface IFMD006.
    But i dont know where to find the interface.
    I have tried in SE24.. but it says the object does not exist..
    Is there any ways to find the Interface IFMD006.
    Please help me..
    Thanks,
    Gokul.

    Hi!
    If you mean a substitution for FI on this, then you gotta check out this link:
    Anyways, don't post everything 3 times!
    Anyways, don't post everything 3 times!
    Anyways, don't post everything 3 times!
    Regards
    Tamá

  • Doubt on Interface

    AnInterface ai = new AnInterfaceImpl();
    where AnInterface is an interface and AnInterfaceImpl is the class which implements AnInterface
    Does it make any sense do this?What is the purpose of a statement like this

    Means you can replace AnInterfaceImpl with some other class that implements AnInterface, without making any changes to code that uses 'ai'. JDBC is a good example of this in action.

  • Doubt in interface...

    interface I {
    int f(int x);
         int var = 4;
    public class C implements I {
    public int f(int x) {
    return x * x;
    public static void main(String[] args) {
         try
    I[] a = new C[I.var];
              System.out.println(a.length);
              System.out.println(a[0]);     //output - null
              System.out.println(a[1]);     //output - null
              System.out.println(a[2]);     //output - null
              System.out.println(a[3]);     //output - null
    for (int i=0; i<a.length; ++i)
    System.out.println(a.f(i));     // Null pointer exception
    }catch (Exception e){
              System.out.println("Error: "+e.getMessage());// error in this line
              e.printStackTrace();
         }//catch
    }//main
    }//class
    question: i have to call f() which is in interface a.length times. how?

    Multiple-post
    http://forum.java.sun.com/thread.jspa?threadID=5173053&tstart=0
    Original has formatting

  • Interface doubts

    hi all,
      i have 2 doubts in interfaces in OO ABAP
    1. do all the methods in interface are by default abstract
    2. do all the methods have to be compulsorily implemented
    Regards,
    N Manjrekar

    Hi,
    No all methods in interface are not default abstract.
    i think all the methods of interfaces have to be implemented in the class.oterwise u will get error implementation missing for method.
    Regards,
    Sruthi

  • Interfaces in Java

    I have a doubt about interfaces. All interface in Java has empty methods, I mean,the methods dont have any implementation. So, to use these methods, there has to be a class that implements this interface in order these methods to have an implementation. Here is my question: there are some Interfaces in Java like java.sql.Statement that dont have any class that implements its methods and in spite of this, I can call the methods of the interface. How is this possible?
    Thanks

    Yes there is always an implementation. You just aren't necessarily exposed to the actual class which implements the interface, but you can tell what the class is like this:
    Statement stmt = ...; // get your Statement however you are doing it now
    System.out.println("Actual class implementing Statement interface in this case is: " + stmt.getClass());

  • Interfaces in JDBC

    Hi Everyone
    i have a doubt regarding interfaces in JDBC api.my question is why SUN has made Connection,Statement,Resultset etc as interfaces in jdbc.why have they not made them as simple classes.Is there any specific reason behind this thing unless it is sun specific.plesae provide me your comments on the same.
    regards
    kvikram

    This leaves more freedom to the implementors of the very drivers. They can inherit their implementing classes from some internal classes if they wish, which would not be the case if it were an abstract class and not an interface.
    Abstract classes ususally contain some non-complete implementation, interfaces are "just" interfaces. The JDBC very much fits to interfaces.
    So there is no reason for them to be abstract classes and there are reasons for them to be interfaces.

  • Problem in Interface

    Hi,
    I doubt in Interface.
    Interface means : Only Method declaration & static final variable, there is no implementation of the methods. When we use it in the class, then we have to implement that method in our class, insted of that we can directly write that method.
    Regards
    DRA

    Interfaces are also commonly used to holdconstants.
    This is a bad idea.Here's one explanation why:
    Effective Java - Joshua Bloch, Chapter 4, Item #17: Use interfaces only to define types.
    The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface.

  • Regarding interfaces?

    Mapping data for interfaces between SAP and Non-SAP systems?
    What are the things involved in it
    Please explain me and if you have any documents regarding pls let me know
    pls forward the doc if any to [email protected]

    satishnarayan wrote:
    HI
    I have doubt regarding interface concept.That is in my interface 7 methods are already available.that interface was implementd by 3 classes.like class a,class b,class c.in future i will add some extra method to that interface but that method will usefull only in class a
    but it will not usefull in class b, class c. how can i achieve this type of scenario.plese give the answer.
    Thanks and regardsAccording to your example the additional methods should NOT be added to the interface. An interface should only include the methods relevant to all of the classes implementing it. Any method not related to theinterface itself should not be in there.
    Add your methods to class a or create a second interface declaring the methods you need.

Maybe you are looking for

  • Problem with external Lacie disk

    Hi! I have some serious problems with my Lacie 250GB Porche disk. The disk shows up on my desktop but it does not allow me to read and write to it. Apple's disk tool does not manage to fix the disk. I have tried running Diskwarrior, but it gives me a

  • Can't edit members of my group message?  4S / iOS 8.1

    Up to date iPhone 4S user. I can add people to a group message, but if I go to details and swipe to delete on a name nothing happens...I can't seem to delete a user from the chat. (a friend asked to be removed from a particular group) Also to see if

  • TDM vi's work in Admin account, but not Limited user

    I have an app that I wrote using the TDM VIs that works perfectly in the development environment and as an executable in an Admin account in WindowsXP. I am trying to deploy the app for use in a limited user account, and I am getting an error about a

  • Array in Map

    Is it possible to put an arry into a HashMap? Map paramMap=request.getParameterMap(); String[] Str = (String[]) paramMap.get("lang"); It does return a String[]. In the map the values are put in array form. I want to modify the value of "lang" in the

  • Portlet error message

    Hi, I created a portlet by web service wizard from BEA, and deployed it into a multi-page portal, but when I switched to the page from another page, I got a error message as attached file, any idea about this? Thanks a lot. [portlet_error.bmp]