MAQ Interview Question for Applications Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
4
of 4 vote

This is what I found from Oracle Website-

"If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile."

Answer to your question:
Class C will compile and run successfully. No error it works fine

As method max() has same signature in both Interfaces, we'll treat it as a single abstract method and define it only once.
Compiler will check if you implemented the methods declared in Interfaces.
As per the contract you did.

There is no question of Run time error as Interface doesn't have definition of method max()

- Mohsin Tejani October 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

Works fine.

interface A
{
void m();
}
 
interface B
{
void m();
}
 
class Test implements A,B
{
        public void m()
        {
                System.out.println("Done");
        }
 
        public static void main(String[] args)
        {
                Test t=new Test();
                t.m();
        }
}

- HS August 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if we want to use any particular method we need to give the fully qualified name of the interface

- rohit August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Rohit, what do you mean? As is in "m() from which interface" is called?

- dc360 August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

interface A
{
void m();
}

interface B
{
void m();
}

class Test implements A,B
{
public void A.m()
{
System.out.println("Done");
}
public void B.m()
{
System.out.println(" ok Done");
}

public static void main(String[] args)
{
Test ob=new Test();
A.m ao=ob;
B.m bo=ob;
ao.m();
bo.m();


}
}

- Anonymous September 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Have you tried compiling this code? It don't think it will go through.
I have not seen anything like 'public void A.m()' so far in Java, let me know if I am missing anything here.

- Anonymous September 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Multiple inheritence isnt alloed in Java, but note this is not Java code as said in ques.

- Anonymous September 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

At least in C#, it will compile and run just fine.
When implementing an interface, you need to comply with the method headers that are defined in the interfaces. If you implement 2 interfaces, then as long as you implement the methods (headers can be the same), then you're just fine.

For instance, the following will compile and run just fine:

class Program
    {
        static void Main(string[] args)
        {
            C c = new C();
            c.f(); //this will run just fine, and type bbbb
        }
    }

    interface A
    {
        void f();
    }

    interface B
    {
        void f();
    }

    class C : A, B
    {
        public void f()
        {
            Console.WriteLine("bbbb");
        }
    }

- Idan October 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Interface is contract ! If any class implements any interface they just are supposed to implements all the methods with same signature which satisfies the contract.

Here is this case the implemented does satisfied A, B contract and thus it will not be any problem.

- sansor October 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

there is no problem in compiling and running this code with java

- Anonymous September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public interface A {
void m();
}


public interface B {
void m();
}


public class mainTest {
public static void main(String []args)
{
Test t = new Test();
t.m();
}

}


public class Test implements A,B {

@Override
public void m() {
// TODO Auto-generated method stub
System.out.println("University Of Delhi , India");

}

}

- Amarkant Kumar October 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i thnik it will give runtime exception .we have to give alias of the interfaces so that particular method will be called for particular interface

- knit.ranjeet October 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

its 100% Compilation error because JAVA doesn't support multiple inheritance so it will get the compilation error.

- surya kiran November 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yeah there is no issue with this code in c#


using System;

public interface IA
{
void m();
}

public interface IB
{
void m();
}

public class Program : IA,IB
{
public void m()
{
Console.WriteLine("hello");
}

public static void Main()
{
Program p = new Program();
p.m();
}
}

- a.varadachari August 30, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More