Menu
Topics Index
...
`

Interface Rules


If you need explanation Read this topic

If you need Answer Take test on this topic

Interface Rules
What will be the output of the following program?
public class I1 {
    public static void main(String[] args) {
        A a = new A();
        a.m1();
        a.m4();
        a.m2();
    }
}
interface I {
    void m1();
    void m4();
}
interface I2 {
    void m2();
}
class A implements I, I2 {
    public void m1() {
        System.out.print("1");
    }
    public void m2() {
        System.out.print("2");
    }
    public void m3() {
        System.out.print("3");
    }
    public void m4() {
        System.out.print("4");
    }
}
abstract class B implements I2 {
    public void m1() {}
    public void m2() {
        System.out.print("5");
    }
    void m3() {}
}

A. 142
B. 143
C. 12345
D. Compilation Error or Runtime Error
Topic: Creating Interface In Java With Example Program

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Option A .... class A object created ... followed by function calls to m1() , m4() , m2 () .... since class A implements the interfaces.. the definitions for the functions are present in class leading to printing of 142

Posted by Kittu Manoj    2014-08-20 08:43:35


ans a.
m1 cald n 1 printd .
m4 cald prints 4
m2 cald 2 printd

Posted by Maheshwari Natarajan    2014-08-20 08:45:21


A

Posted by Vineeth Parasa    2014-08-20 08:56:40


A

Posted by Raviteja Daggupati    2014-08-20 09:55:06


Congratulations Kittu Manoj. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-21 05:16:30


© meritcampus 2019

All Rights Reserved.

Open In App