Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
iphone x used
AssassiN1
Updated:
Yesterday at 10:30 PM
කිතුල් තලප
Manoj Suranga Bandara
Updated:
Saturday at 7:04 PM
Ad icon
ව්යාපාර, Tuition පන්ති සහ Personal Portfolios සඳහා Web Setup එකක් රු. 9,099/- කට (වාර්ෂික renewal ර
thathsilura
Updated:
Thursday at 6:17 PM
AWS Certified Solutions Architect-Associate + AWS Certified Cloud Practitioner
Sanjeewani95
Updated:
Aug 19, 2026
🚀 එක පැකේජ් එකයි - මාසෙටම Unlimited Internet! 🌐
sayuru bandara
Updated:
Aug 18, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
java help needed
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="sihina_lahiru" data-source="post: 7285029" data-attributes="member: 149577"><p><strong>Java Interface example</strong></p><p></p><p> </p><ol> <li data-xf-list-type="ol">/*</li> <li data-xf-list-type="ol">Java Interface example.</li> <li data-xf-list-type="ol">This Java Interface example describes how interface is defined and </li> <li data-xf-list-type="ol">being used in Java language.</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol">Syntax of defining java interface is,</li> <li data-xf-list-type="ol"><modifier> interface <interface-name>{</li> <li data-xf-list-type="ol"> //members and methods()</li> <li data-xf-list-type="ol">}</li> <li data-xf-list-type="ol">*/</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol">//declare an interface</li> <li data-xf-list-type="ol">interface IntExample{</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol"> /*</li> <li data-xf-list-type="ol"> Syntax to declare method in java interface is,</li> <li data-xf-list-type="ol"> <modifier> <return-type> methodName(<optional-parameters>);</li> <li data-xf-list-type="ol"> IMPORTANT : Methods declared in the interface are implicitly public and abstract.</li> <li data-xf-list-type="ol"> */</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol"> public void sayHello();</li> <li data-xf-list-type="ol"> }</li> <li data-xf-list-type="ol">}</li> <li data-xf-list-type="ol">/*</li> <li data-xf-list-type="ol">Classes are extended while interfaces are implemented.</li> <li data-xf-list-type="ol">To implement an interface use implements keyword.</li> <li data-xf-list-type="ol">IMPORTANT : A class can extend only one other class, while it </li> <li data-xf-list-type="ol">can implement n number of interfaces.</li> <li data-xf-list-type="ol">*/</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol">public class JavaInterfaceExample implements IntExample{</li> <li data-xf-list-type="ol"> /*</li> <li data-xf-list-type="ol"> We have to define the method declared in implemented interface,</li> <li data-xf-list-type="ol"> or else we have to declare the implementing class as abstract class.</li> <li data-xf-list-type="ol"> */</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol"> public void sayHello(){</li> <li data-xf-list-type="ol"> System.out.println("Hello Visitor !");</li> <li data-xf-list-type="ol"> }</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol"> public static void main(String args[]){</li> <li data-xf-list-type="ol"> //create object of the class</li> <li data-xf-list-type="ol"> JavaInterfaceExample javaInterfaceExample = new JavaInterfaceExample();</li> <li data-xf-list-type="ol"> //invoke sayHello(), declared in IntExample interface.</li> <li data-xf-list-type="ol"> javaInterfaceExample.sayHello();</li> <li data-xf-list-type="ol"> }</li> <li data-xf-list-type="ol">}</li> <li data-xf-list-type="ol"> </li> <li data-xf-list-type="ol">/*</li> <li data-xf-list-type="ol">OUTPUT of the above given Java Interface example would be :</li> <li data-xf-list-type="ol">Hello Visitor !</li> <li data-xf-list-type="ol">*/</li> </ol></blockquote><p></p>
[QUOTE="sihina_lahiru, post: 7285029, member: 149577"] [B]Java Interface example[/B] [LIST=1] [*]/* [*]Java Interface example. [*]This Java Interface example describes how interface is defined and [*]being used in Java language. [*] [*]Syntax of defining java interface is, [*]<modifier> interface <interface-name>{ [*] //members and methods() [*]} [*]*/ [*] [*]//declare an interface [*]interface IntExample{ [*] [*] /* [*] Syntax to declare method in java interface is, [*] <modifier> <return-type> methodName(<optional-parameters>); [*] IMPORTANT : Methods declared in the interface are implicitly public and abstract. [*] */ [*] [*] public void sayHello(); [*] } [*]} [*]/* [*]Classes are extended while interfaces are implemented. [*]To implement an interface use implements keyword. [*]IMPORTANT : A class can extend only one other class, while it [*]can implement n number of interfaces. [*]*/ [*] [*]public class JavaInterfaceExample implements IntExample{ [*] /* [*] We have to define the method declared in implemented interface, [*] or else we have to declare the implementing class as abstract class. [*] */ [*] [*] public void sayHello(){ [*] System.out.println("Hello Visitor !"); [*] } [*] [*] public static void main(String args[]){ [*] //create object of the class [*] JavaInterfaceExample javaInterfaceExample = new JavaInterfaceExample(); [*] //invoke sayHello(), declared in IntExample interface. [*] javaInterfaceExample.sayHello(); [*] } [*]} [*] [*]/* [*]OUTPUT of the above given Java Interface example would be : [*]Hello Visitor ! [*]*/ [/LIST] [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom