Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java interfaces implementation

Have Programming Question? Ask it here!
 
 
 


mazeed
java interfaces implementation
2 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


hai

I have defined one inter face like Maths taking methods like add(), sub(), mul()in interface

I take different implementation classes for add() method and sub()and mul()

 when i trying to implement add()mthod in Addition class it is asking sub() and mul() methods which are define in Maths interface. I want only addition implementation in addition class

how to resolve this


Advertisement
View Answers

June 3, 2011 at 4:40 PM


If you are implementing an interface in your java code, then you need to implement all its methods in a class. But if you want to use only add() method in your Addition class then implement three interfaces in your java code with three different methods.

Check the given code:

interface Maths1{
     void add();
}
interface Maths2{
     void sub();
}
interface Maths3{
     void mul();
}

class Addition implements Maths1 {
  public void add() {
    int a=6,b=4;
    int sum=a+b;
    System.out.println(sum);
  }
}
class Subtraction implements Maths2 {
  public void sub() {
    int a=6,b=4;
    int diff=a-b;
    System.out.println(diff);
  }
}
class Multiplication implements Maths3 {
  public void mul() {
    int a=6,b=4;
    int multiply=a*b;
    System.out.println(multiply);
  }
}
public class InterfaceExample{
  public static void main(String[]args){
      Addition a=new Addition();
      a.add();
      Subtraction s=new Subtraction();
      s.sub();
      Multiplication m=new Multiplication();
      m.mul();
     }
  }


June 3, 2011 at 4:55 PM


thank you



Related Tutorials/Questions & Answers:
java interfaces implementation
java interfaces implementation  hai I have defined one inter face... different implementation classes for add() method and sub()and mul() when i trying... which are define in Maths interface. I want only addition implementation
Implementation code inside interfaces
Implementation code inside interfaces 2001-01-25 The Java Specialists' Newsletter [Issue 006] - Implementation code inside interfaces Author: Dr. Heinz... email or RSS. Welcome to the 6th issue of "The Java(tm) Specialists
Advertisements
Java interfaces
Java interfaces  What interface must an object implement before it can be written to a stream as an object
java interfaces
java interfaces  sample code for multiple interface   interface A { void test(int i); } interface B { void test(String s); } public class MultipleInterface implements A, B { public void test(int i
Marker interfaces in java
Marker interfaces in java  how marker interfaces work
interfaces - Java Beginners
, super class constructor runs.what about interfaces?  Hi Friend... is called the base class or the parent class. To derive a class in java the keyword... to : http://www.roseindia.net/java/language/inheritance.shtml Thanks
Interfaces - Java Interview Questions
Interfaces  two interfaces having same method names and these two interfaces are implemented by a single class. so now i would like to generate different code of same methods of different interfaces. eg: ---- interface i1
Interfaces - Java Interview Questions
Interfaces  two interfaces having same method names and these two interfaces are implemented by a single class. so now i would like to generate different code of same methods of different interfaces in single class? my query
how to create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
interfaces
& interfaces.   An interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement
interfaces - Java Beginners
interfaces  examples on interfaces  Hi Friend, Please visit the following links: http://www.roseindia.net/java/master-java/interface.shtml http://www.roseindia.net/java/java-exception/create-interface.shtml
java native implementation
java native implementation  What is java native implementation
filter implementation in java
filter implementation in java   How to implement filters in java?   Java - filter implementation Tutorials Filter Files in Java Response Filter Servlet Example
Question in Array Implementation (java) ??!
Question in Array Implementation (java) ??!  Good Morning EveryOne I have Q in Java - and if any One have the Answers please tall me ??!! Question is : 1- Create a class called ‚??PhoneEntry‚?? which can be used to store
java implementation - Java Beginners
java implementation  Im M.Phil research scholar,i need a software testing module implemented in java.My research area is software testing,if anyone could help me out
Java implementation problem
Java implementation problem  I want to implement following in java code : Main thread 1. create three threads 2. wait for completion of stage 2.../answers/viewqa/Java-Beginners/28578-java-implementation-problem-.html
java implementation problem
java implementation problem   I want to implement following in java code : Main thread Create three threads wait for completion of stage 2 of all three threads Access all three local variable (LC0, LC1, LC2) of threads bulid
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
Progress Bar implementation in Java Script
Progress Bar implementation in Java Script  Hi Friend, I am new to Java Script, but i want implement the progress bar in my html by reading the value from file (like value=30) and the value in file be changing from 0 to 100
java code implementation - Java Beginners
java code implementation  I am writing a java program, voteCounter the program is in two classes; one is the main class, voteCounter.java, and the other is voteCounterPanel.java. what it basically does is when the user presses
linked lists implementation - Java Beginners
, there are no preconditions. Write the code for the method for a linked implementation (without tail
Stack Implementation java code - Java Beginners
Stack Implementation java code  Hello roseindia and java experts can u help me.can you give me a code for this sir/maam.thank you so much. STACK IMPLEMENTATION -expression evaluator *GIVEN a String of expression, create
What are the different types of interfaces in java? - Java Interview Questions
What are the different types of interfaces in java?  Hi, Is it correct question.I faced this in one interview. If yes can u tell me please. thanks chandu
Simple Hash Table implementation in Java
Simple Hash Table implementation in Java   ... implementation from the basic in Java. In this section, you will see how... the given title exists or not. This section is very helpful for your java
Overview of Networking through JAVA,Getting list of Local Interfaces on a machine
Getting list of Local Interfaces on a machine... to find out the total no of list of local interfaces available on a machine. Here... the local interfaces which are instances of NetworkInterface class and displays
EJB Interfaces
EJB Interfaces       Interface in java means a group of related methods with empty bodies. EJB have generally 4 interfaces. These are as follows 1)Remote interface:- Remote interface
Interfaces in flex
Interfaces in flex  Hi..... Please tell me about... What are - IStyleClient, IChildList, ILayoutManager, IToolTipManagerClient, IInvalidating, IValidatorListener, IFlexModule, IAutomationObject, IPropertyChangeNotifier
EJB Interfaces
EJB Interfaces       Interface in java means a group of related methods with empty bodies. EJB have generally 4 interfaces. These are as follows 1)Remote interface:- Remote interface
What are Callback interfaces?
What are Callback interfaces?  Hi, What are Callback interfaces? thanks
Object-Oriented Implementation of Numerical Methods - Java Tutorials
Object-Oriented Implementation of Numerical Methods 2002-04-01 The Java Specialists' Newsletter [Issue 044] - Review: Object-Oriented Implementation... of The Java(tm) Specialists' Newsletter, sent to 3101 (!) Java experts in over
Interfaces and Abstract Classes - Development process
Interfaces and Abstract Classes  What are the Scenarios where we use Interface and Abstract Classes?  Hi Friend, Interface: Java does... by using the interface. Interfaces are useful when you do not want classes
Java: Interfaces
Java: Interfaces An interface is a list of methods that must be defined... does, but abstract classes do allow static method definitions, and interfaces... different interfaces. If a class doesn't define all methods of the interfaces
Hibernate Callback interfaces
Hibernate Callback interfaces  What are Callback interfaces?   Callback interfaces allow the application to receive a notification when something interesting happens to an object?for example, when an object is loaded
Summary: Classes, Interfaces
Java: Summary: Classes, Interfaces Packages package package-name; Class Definition A class definition prototype: visibility class class-name [extends parent-class] [implements interface-name...] { class-body } nameMeaning
interfaces,exceptions,threads
interfaces,exceptions,threads  SIR,IAM JAVA BEGINER,I WANT KNOW THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface... class. In java, multiple inheritance is achieved by using the interface
can i estimate estimate execution time for a method without knowing implementation details of a method - Java Interview Questions
can i estimate estimate execution time for a method without knowing implementation details of a method  hi all, can i estimate estimate execution time for a method without knowing implementation details of a method. Thanks
Collection Interfaces
Collection Interfaces     ... of several interfaces, and classes that implement those interfaces, contained within... of objects.  Different interfaces describe different types of functionalities
VoIP Implementation
VoIP Implementation VoIP Implementation Tour We?re packing our... is launching the Voice on VOIP Implementation Tour 2004-one-day workshops...-telephony is essentially a non-starter.    VoIP Implementation
What are the Core interfaces are of Hibernate framework?
What are the Core interfaces are of Hibernate framework?  Hi, What are the Core interfaces are of Hibernate framework? Thanks
Hibernate: core interfaces of hibernate framework
Hibernate: core interfaces of hibernate framework  What are the core interfaces of hibernate framework   Most of hibernate based application code deals with following interfaces provided by the Hibernate Core
String Class implementation in API
String Class implementation in API  Hi all, I was confused ,when am looking into java String class single argument constructor into that we are passing again String as parameter.How is it possible,any one can help me how can
implementation object in C
implementation object in C  how to create and implement an object in C
Java API
Java API       Java API Java API is not but a set of classes and interfaces that comes with the JDK. Java API is actually a huge collection of library
Bar chart implementation in PHP
Bar chart implementation in PHP  How to implements reports in bar graphs by using PHP
Interface in Java
Interface in Java       In this section we will learn about Interface and Marker Interfaces in Java... is also the interface's example. But in java programming language interface
Jep's Rich User Interfaces blog
Jep's Rich User Interfaces blog       About AJAX Performance and some other things by Jep Castelein of Backbase Read full Description
Linked list implementation
Linked list implementation  How to create linkedlist by using array in java? and also How to manipulate
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
jsp plugin implementation - Applet
, Java BooksStore's   Java Bookstore
jsp plugin implementation - Applet
folder under the WEB-INF folder and put my java code file and its corresponding... NOT INITED error displayed in my status bar. I opened the java console. The error
Advertisements
 

 

 

DMCA.com