suppose we have an interface & that interface contains five
methods. if a class implements that interface then we have
to bound that to give tha definition of all five methods in
that class. If we declare that class as abstract then can
we call only two methods to give the deinition of that
method & i don't want to give the definition of all the
methods? can it possible

Answer Posted / sitaram

yes it is possible, just make rest of the method abstract
explicitly.


public interface InterfaceSample {
public void method1();
public void method2();
public void method3();
public void method4();
}

abstract class Abstclass implements InterfaceSample{
public abstract void method1();
public abstract void method2();
public void method3(){
System.out.println(" astract method3 ..............");
}
}
public class Sample extends Abstclass {
public void method1(){
System.out.println("method1 ..............");
}
public void method2(){
System.out.println("method2 ..............");
}
public void method4(){
System.out.println("method4 ..............");
}

public static void main(String[] args) {
Sample s1 = new Sample();
s1.method1();
s1.method2();
s1.method3();
s1.method4();
}

}

Is This Answer Correct ?    0 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the static method?

571


Why string objects are immutable in java?

567


What is the difference between a choice and a list?

608


Can we override the overloaded method?

566


What are the kinds of polymorphism?

614






Can we have any other return type than void for main method?

540


How can we create a synchronized collection from given collection?

589


When object is created and destroyed?

640


What is a final class in java?

545


How big is a pointer?

555


When would you use a static class?

584


What is character in data type?

553


Can Exception handling we can handle multiple catch blocks?

646


Can a serialized object be transferred via network?

519


How to use Media tracker Class.

648