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
Handmade Character Soft Toys
anil1961
Updated:
Tuesday at 2:11 PM
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Sunday at 3:05 AM
Power Lifting Lever Belt
SkullVamp
Updated:
Jun 13, 2026
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Jun 13, 2026
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Jun 11, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
ElaKiri Programmer's Club
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="tery123" data-source="post: 18407152" data-attributes="member: 343391"><p>[PHP]/** </p><p> *class : InherianceStudy </p><p> *Author : Kanishka Dilshan </p><p> *Purpose: Demonstrate inheritance in Java </p><p> *Blog : http://javaxclass.blogspot.com </p><p> */ </p><p> </p><p>class Parent { </p><p> protected int i,j; </p><p> </p><p> public Parent(){ </p><p> System.out.println("Using the default constructor of Parent class.."); </p><p> i=0; </p><p> j=0; </p><p> } </p><p> </p><p> public Parent(int i,int j){ </p><p> System.out.println("Using the integer constructor of Parent class.."); </p><p> this.i=i; </p><p> this.j=j; </p><p> } </p><p> </p><p> public void showMessage(String msg){ </p><p> System.out.println("A message from Parent class.."); </p><p> System.out.println("Message : "+msg); </p><p> } </p><p>} </p><p> </p><p>class Child extends Parent { </p><p> protected String text; </p><p> </p><p> public Child(){ </p><p> System.out.println("Using the default constructor of Child class.."); </p><p> } </p><p> </p><p> public Child(int i,int j,String t){ </p><p> super(i,j); </p><p> System.out.println("Using the integer constructor of Child class.."); </p><p> this.text=t; </p><p> } </p><p> </p><p> public void showMessage(){ </p><p> showMessage("Java programming is very interesting!!"); </p><p> System.out.println("A message from Child class.."); </p><p> System.out.println("Message : "+text); </p><p> } </p><p>} </p><p> </p><p>class InherianceStudy { </p><p> public static void main(String args[]){ </p><p> System.out.println("Creating Parent objects..."); </p><p> System.out.println("_________________________________________________\n"); </p><p> Parent p1=new Parent(); </p><p> Parent p2=new Parent(2,5); </p><p> System.out.println("\nCreating Child objects..."); </p><p> System.out.println("_________________________________________________\n"); </p><p> </p><p> Child c1=new Child(); </p><p> Child c2=new Child(3,-1,"Java is owned by Sun Microsystems"); </p><p> System.out.println("\nShowing messages.."); </p><p> System.out.println("_________________________________________________\n"); </p><p> c2.showMessage(); </p><p> } </p><p>} [/PHP]</p><p></p><p><img src="http://i61.tinypic.com/34snh3t.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p></p><p>me out put eke kiyanaw awidyata parent class eken methods and constructors inherit wenawane...oya <span style="color: Red">c2.showMessage();</span> kiyana eka wada karana widiya tikaka pahadala dennako danna kenek...</p></blockquote><p></p>
[QUOTE="tery123, post: 18407152, member: 343391"] [PHP]/** *class : InherianceStudy *Author : Kanishka Dilshan *Purpose: Demonstrate inheritance in Java *Blog : http://javaxclass.blogspot.com */ class Parent { protected int i,j; public Parent(){ System.out.println("Using the default constructor of Parent class.."); i=0; j=0; } public Parent(int i,int j){ System.out.println("Using the integer constructor of Parent class.."); this.i=i; this.j=j; } public void showMessage(String msg){ System.out.println("A message from Parent class.."); System.out.println("Message : "+msg); } } class Child extends Parent { protected String text; public Child(){ System.out.println("Using the default constructor of Child class.."); } public Child(int i,int j,String t){ super(i,j); System.out.println("Using the integer constructor of Child class.."); this.text=t; } public void showMessage(){ showMessage("Java programming is very interesting!!"); System.out.println("A message from Child class.."); System.out.println("Message : "+text); } } class InherianceStudy { public static void main(String args[]){ System.out.println("Creating Parent objects..."); System.out.println("_________________________________________________\n"); Parent p1=new Parent(); Parent p2=new Parent(2,5); System.out.println("\nCreating Child objects..."); System.out.println("_________________________________________________\n"); Child c1=new Child(); Child c2=new Child(3,-1,"Java is owned by Sun Microsystems"); System.out.println("\nShowing messages.."); System.out.println("_________________________________________________\n"); c2.showMessage(); } } [/PHP] [IMG]http://i61.tinypic.com/34snh3t.png[/IMG] me out put eke kiyanaw awidyata parent class eken methods and constructors inherit wenawane...oya [COLOR="Red"]c2.showMessage();[/COLOR] kiyana eka wada karana widiya tikaka pahadala dennako danna kenek... [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom