Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Interfaces  (Read 991 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: February 08, 2009, 11:10:33 AM »

Java version
http://www.engineeringser...rface_how_to-t2882.0.html

c# version

Interface1.cs
Code
GeSHi (csharp):
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ComputerInterfaceDemo
  7. {
  8.    interface IComputerInterface
  9.    {
  10.        void startUp();
  11.        void shutDown();
  12.    }
  13. }
  14.  
Created by GeSHI 1.0.7.20

Program.cs
Code
GeSHi (csharp):
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ComputerInterfaceDemo
  7. {
  8.    class Program : IComputerInterface
  9.    {
  10.        static void Main(string[] args)
  11.        {
  12.            Program p = new Program();
  13.            p.startUp();
  14.            p.shutDown();
  15.            Console.Read();
  16.        }
  17.  
  18.        public void startUp()
  19.        {
  20.            Console.WriteLine("Start up");
  21.        }
  22.  
  23.        public void shutDown()
  24.        {
  25.            Console.WriteLine("Shut down");
  26.        }
  27.    }
  28. }
  29.  
Created by GeSHI 1.0.7.20

As you can see, not much difference between Java and c# except in Java you use the "implements" keyword to implement the interface while in c# you do this with a ":" and the Interface should start with "I" as in "IComputerInterface", this is a c# naming convention but it's not required to name Interfaces with a capital I but however i would recommend to start all interfaces with a capital I.
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here