please solve the java puzzle and give soiution with reason
what wil be the output for this. please help me...
abstract class test
{
abstract void add(int x,int y);
}
interface inter
{
void add(int x,int y);
}
class testMain extends test implements inter
{
public static void main(String arg[])
{
public void add(int x,int y)
{
system.out.println(x+y);
}
}
testMain t=new testMain();
t.add(2,4);
}
}
my doubt is what wil call either abstract class or interface.
i don`t know the answer.
please help me.
thanking you java tiger
When (or if) you deal with the syntax problems and repost, could you use the "code" tags? They are described here: http://forum.java.sun.com/help.jspa?sec=formatting
The idea is that you put [code] at the start of your code and [/code] at the end. That way your code remains readable when it appears in the forum.
For instance:
[code]if(tagsUsed) {
outputGood = true;
}[/code]
will appear like:
if(tagsUsed) {
outputGood = true;
}
Your code has lot of errors i have edited it.
abstract class test
{
abstract void add(int x,int y);
}
interface inter
{
void add(int x,int y);
}
class testMain extends test implements inter
{
public static void main(String arg[])
{
/*
public void add(int x,int y)
{
system.out.println(x+y);
}
*/
testMain t=new testMain();
t.add(2,4);
}
/*
testMain t=new testMain();
t.add(2,4);
*/
public void add(int x,int y)
{
System.out.println(x+y);
}
//}
}
Just go through the code and try to get the which one abstract class or interface is used.just try out by commenting and compiling code over and over again,you will find the answer!
Good luck
ram102125.
> What's the difference
> between calling something and implementing something?
What's the difference between using a car and builing a car?
This "calling interface" is complete BS. You're invoking a method on an instance of a concrete class stored in a reference. A reference who's type may be an interface or an abstract class or whatever. So you're not "calling an interface".