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
Ad icon
Sell your Land, House on idamata.lk for FREE
sajith.xp.pk
Updated:
Yesterday at 9:03 AM
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
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: 18407030" data-attributes="member: 343391"><p>[PHP]/** </p><p> *class : Cube </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> </p><p>class Cube { </p><p> protected int length; </p><p> protected int width; </p><p> protected int height; </p><p> </p><p> public Cube(int l,int w,int h){ </p><p> length=l; </p><p> width=w; </p><p> height=h; </p><p> } </p><p> </p><p> public void setLength(int l){ </p><p> length=l; </p><p> } </p><p> </p><p> public void setWidth(int w){ </p><p> width=w; </p><p> } </p><p> </p><p> public void setHeight(int h){ </p><p> width=h; </p><p> } </p><p> </p><p> public int getVolume(){ </p><p> return(length*width*height); </p><p> } </p><p> </p><p> public void showInfo(){ </p><p> System.out.println("Length \t:"+this.length); </p><p> System.out.println("Width \t:"+this.width); </p><p> System.out.println("Height \t:"+this.height); </p><p> System.out.println("Volume \t:"+getVolume()); </p><p> } </p><p>} [/PHP]</p><p></p><p>[PHP]/** </p><p> *class : ColorCube </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 ColorCube extends Cube { </p><p> String color; </p><p> </p><p> public ColorCube(int l,int w,int h,String color){ </p><p> //constructing the parent </p><p> super(l,w,h); </p><p> this.color=color; </p><p> } </p><p> </p><p> public void setColor(String color){ </p><p> this.color=color; </p><p> } </p><p> </p><p> public void showInfo(){ </p><p> super.showInfo(); </p><p> System.out.println("Color \t:"+this.color); </p><p> } </p><p>} [/PHP]</p><p></p><p>[PHP]/** </p><p> *class : InheritanceDemo </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 InheritanceDemo { </p><p> public static void main(String args[]){ </p><p> Cube cube1=new Cube(3,7,5); </p><p> ColorCube ccb1=new ColorCube(2,9,4,"Blue"); </p><p> </p><p> cube1.showInfo(); </p><p> System.out.println("_____________________________"); </p><p> ccb1.showInfo(); </p><p> </p><p> System.out.println("\nMaking changes to cube objects...."); </p><p> cube1.setWidth(8); </p><p> ccb1.setColor("Yellow"); </p><p> ccb1.setHeight(6); //this methods is inherited by the Cube class </p><p> System.out.println("New info. of modified objects\n"); </p><p> cube1.showInfo(); </p><p> System.out.println("_____________________________"); </p><p> ccb1.showInfo(); </p><p> } </p><p>} [/PHP]</p><p></p><p>menna meke out put eke waradak thiyenawada???</p><p></p><p><img src="http://i60.tinypic.com/8wm6c0.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p></p><p>meke <span style="color: red">ccb1 kiyana object </span>eke out put eka <span style="color: Red">2,9,6,108 ,yello</span> neda???dewini para modify kalahama????</p></blockquote><p></p>
[QUOTE="tery123, post: 18407030, member: 343391"] [PHP]/** *class : Cube *Author : Kanishka Dilshan *Purpose: Demonstrate inheritance in Java *Blog : http://javaxclass.blogspot.com */ class Cube { protected int length; protected int width; protected int height; public Cube(int l,int w,int h){ length=l; width=w; height=h; } public void setLength(int l){ length=l; } public void setWidth(int w){ width=w; } public void setHeight(int h){ width=h; } public int getVolume(){ return(length*width*height); } public void showInfo(){ System.out.println("Length \t:"+this.length); System.out.println("Width \t:"+this.width); System.out.println("Height \t:"+this.height); System.out.println("Volume \t:"+getVolume()); } } [/PHP] [PHP]/** *class : ColorCube *Author : Kanishka Dilshan *Purpose: Demonstrate inheritance in Java *Blog : http://javaxclass.blogspot.com */ class ColorCube extends Cube { String color; public ColorCube(int l,int w,int h,String color){ //constructing the parent super(l,w,h); this.color=color; } public void setColor(String color){ this.color=color; } public void showInfo(){ super.showInfo(); System.out.println("Color \t:"+this.color); } } [/PHP] [PHP]/** *class : InheritanceDemo *Author : Kanishka Dilshan *Purpose: Demonstrate inheritance in Java *Blog : http://javaxclass.blogspot.com */ class InheritanceDemo { public static void main(String args[]){ Cube cube1=new Cube(3,7,5); ColorCube ccb1=new ColorCube(2,9,4,"Blue"); cube1.showInfo(); System.out.println("_____________________________"); ccb1.showInfo(); System.out.println("\nMaking changes to cube objects...."); cube1.setWidth(8); ccb1.setColor("Yellow"); ccb1.setHeight(6); //this methods is inherited by the Cube class System.out.println("New info. of modified objects\n"); cube1.showInfo(); System.out.println("_____________________________"); ccb1.showInfo(); } } [/PHP] menna meke out put eke waradak thiyenawada??? [IMG]http://i60.tinypic.com/8wm6c0.png[/IMG] meke [COLOR="red"]ccb1 kiyana object [/COLOR]eke out put eka [COLOR="Red"]2,9,6,108 ,yello[/COLOR] neda???dewini para modify kalahama???? [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom