More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Method Overriding in JRuby 
 

In this part of JRuby tutorial you will know to implement overriding of methods between the classes.

 

Method Overriding in JRuby

                         

In this part of JRuby tutorial you will know to implement overriding of methods between the classes. In earlier examples of JRuby you have studied a lot about to create class, inheriting class and calling methods of classes. Now in this example we will introduce you with the case of overriding of methods in JRuby program.

In this example we have created a class "Base" and it consists of one method "addBase" and after that we have created another class Derive which consists of one new method addDerive  and one overridden method addBase which have some other functionality rather than Base class by inheriting the Base class.

After creating instances of Base and Derive class when we will call the overridden then it will show you the case of overriding that Base class method is overridden.Here is the example code of OverrideJRuby.rb as follows:

 

 

 OverrideJRuby.rb

# Example program of Inheritance in JRuby

class Base
  def addBase
       puts "Hello Base"
   end
end

class Derive < Base
  def addBase 
       puts "Hello Derived Base"
   end

   def addDerive
      puts "Hello Derived"
   end
end
# Creating instance of Base class
        base = Base.new
        puts base.addBase

# Creating instance of Derive class
       derive = Derive.new
       puts derive.addBase
       puts derive.addDerive

 Output:

C:\JRuby>jruby OverrideJRuby.rb
Hello Base
nil
Hello Derived Base
nil
Hello Derived
nil

Download Source Code

                         

» View all related tutorials
Related Tags: c ruby ide class ant variables scope classes variable sed const constants jruby name using instance ria this id tar

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

helo how to make a program using overriding and
overloading methods

Posted by BB on Tuesday, 10.14.08 @ 14:06pm | #81080

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.