Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

public interface Guard
    void doYourJob();

abstract public class Dog implements Guard {}
Which of the following statements is correct?
A. This code will not compile, because method doYourJob() 
in interface Guard must be defined abstract.
B. This code will not compile, because class Dog 
must implement method doYourJob() from interface Guard.
C. This code will not compile, because in the declaration of class 
Dog we must use the keyword extends instead of implements.
D. This code will compile without any errors.
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.

Ans is we have the interface concept which is the collections of the abstract methods...methods in the interface didn't contain the method defination,interfaces can contain the attributes also which are public,static,final by default, the methods which are defined in the interfaces are by default public abstract we don't need to write the methods as abstract, the class which is implementing the interfaces must override the interfaces methods with access specifier as pubic,if we specify weaker access specifier than compiler will raise an error
next class Dog implementing the nterfaces and did't override the doYourJob() so this method is placed as abstract in the Dog class and Dog is made as abstract so no problem here

Posted by Uday Kumar    2015-03-06 15:31:42

ANS IS D (the code will compile without any errors)

--Here the concept of "interface and abstract class" is used.

--Interface:Java includes a concept called interfaces. A Java interface is a bit like a class, except you can only declare methods and variables in the interface. You cannot actually implement the methods. Interfaces are a way to achieve polymorphism in Java.

Abstract class:Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.

--Here,Guard inteface is defined with the doYourJob() method declaration in it.After that Abstract class Dog is defined which implements the Guard interface.So there is no compilation Error in code.

So,Code will compile without any errors.

Posted by Mânïshå Mùlchåndânï    2015-03-07 13:09:45

This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar, Mânïshå Mùlchåndânï,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Switguy Pawan. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-03-09 01:52:59

© meritcampus 2019

All Rights Reserved.

Open In App