473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Interfacing in java

hi everybody am new to work with java. So please do help to be a successful developer in java.....
My first question is How java can implement interface concept in the place of inheritance? And please tell the steps to implement interface concept?
Aug 10 '08 #1
1 1128
JosAH
11,448 Expert 8TB
If a class C implements an interface I it signs a contract saying: you can treat
me as an I instead of a C. It adds another 'face' to the class. Implmenting a
interface is easy; e.g.

Expand|Select|Wrap|Line Numbers
  1. // the interface:
  2. public interface I
  3.    public int aMethod();
  4.    public int anotherMethod();
  5. }
  6. // the implementing class:
  7. public class C implements I {
  8.    // complete implementation of I
  9.    public int aMethod() { return 42; }
  10.    public int anotherMethod() { return 54; }
  11. }
  12.  
If a class says it implements an interface as in "implements I" but it doesn't
implement all of the methods of the interface, the class must be abstract so
that a derived class can complete the implementation of the interface:

Expand|Select|Wrap|Line Numbers
  1. public abstract class C implements I {
  2.    public int aMethod() { return 42; } // partial implementation of I
  3.    // no implementation of anotherMethod() 
  4. }
  5. public class Derived extends C {
  6.    public int anotherMethod() { return 54; } // completes implementation of I
  7. }
  8.  
This all is completely explained in your textbook; read it.

kind regards,

Jos
Aug 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: 2mc | last post by:
All, I'm getting a better handle on Python and NumPy. I've found solutions to many of my questions. Thanks to all. I would like to interface Python (in WinXP) with another program through...
4
by: Chuck Amadi | last post by:
Hi all Anyone know a good Pygresql Tutorial for Interfacing between Python & Postgresql . Cheers Chuck
12
by: David Walker | last post by:
Hi I have a program which I need to interface with a webpage - the webpage will accept an input (probably a 'post' string from the program) and then will process it and needs to return a value. ...
4
by: Shaurya Anand | last post by:
I would like to know more about Interfacing hardware devices through .NET. We're students and what we're trying to do is control our robots with printer or serial port interfacing... very similar...
3
by: Kevin | last post by:
Hi All I got some good responses from some of you guys regarding me serial port interfacing problem that I posted a little while back. However your help leaded me to this link belo ...
2
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to...
1
by: Neil | last post by:
Our hosting company's server went down a few days ago. After they fixed it, our PHP Page and Database are not interfacing. They are not believing me that I have done nothing on my end in several...
1
by: keliie | last post by:
Hello, I've recently completed a database that tracks my food purchases and inventory and I want to add another piece to the database that tracks sales. Our company's waitstaff enters order...
0
by: adilayub | last post by:
can anyody help me in interfacing USB port in java. please mail me the code if anybody has it. Thanks in advace
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.