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.
Similar Messages
-
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. -
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
VishHi,
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 -
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
} -
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
azharEven 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 :-) -
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:
eaajeThe 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 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 -
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 ManjrekarHi,
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 -
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?
ThanksYes 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()); -
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
kvikramThis 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. -
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
DRAInterfaces 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. -
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
-
Change font size of contact form.
Hi, I have been searching through google and various forums to make a contact form, and I finally have it working. (YAY!) HOWEVER... There's one problem: I don't know how to change the font size. Help?! Here's my action script code: submit_btn.addEve
-
Hi there, Does anyone know if it is possible to get the graphical representation of an XSD into an image format such as BMP, JPG or PNG so that it can then be embedded into documentation (e.g. Word)
-
T.code FEBC: setting the report RFEBIT00, by default.
Hi All, when I launch the t.code FEBC, SAP provides me a list of report among which I've to choose the one I need. But the list doesn't contain the report RFEBIT00..... How to add it to the list? Thanks Gandalf
-
We have a small company that would like to have basic call queuing only. No database lookups or desktop clients required. I was just going to use the BE6K's Native Call Queuing but it looks like the reporting options are limited. And with my short
-
Hi all I would like to know does JSP 2.1 also has a parallel lifecycle to JSF just like JSP 2.0, 1.2 etc, there are not many refrences for the same on the net. Does the unified EL help in merging the JSF 1.2 and JSP 2.1 lifecycles ??? Thanks in advan