I am working with Overriding and Overloading and inheritance. The assignment is to modify a class, begin, so it overrides another class, begin, that it is inheriting. I then have to modify a class, increase, so it overloads the inheriting class. If that doesn't confuse the daylights out of you.
Basically what I need help with is an example that shows how to override and overload methods in classes. Any help is appreciated.
Overloading and Overriding methods in classes
Page 1 of 15 Replies - 868 Views - Last Post: 07 April 2012 - 08:11 PM
Replies To: Overloading and Overriding methods in classes
#2
Re: Overloading and Overriding methods in classes
Posted 06 April 2012 - 09:51 PM
class Animal { void makeNoise() { System.out.printl("noise"); } } class Dog extends Animal { void makeNoise() { System.out.printl("bark"); } } class Cat extends Animal { void makeNoise() { System.out.printl("miaou"); } }
#3
Re: Overloading and Overriding methods in classes
Posted 07 April 2012 - 05:08 AM
Well pbl, that's only half of what he wanted to do. He also wanted to overload as well.
So I think it'd be more like...
Of course not exactly, but it has the overloading too.
Hope it helped!
~Crockeo
So I think it'd be more like...
public class Parent { public void talk() { System.out.println("I'm a parent!"); } public void talk(String s) { System.out.println(s); } } public class Child { public void talk() { System.out.println("I'm a child!"); } }
Of course not exactly, but it has the overloading too.
Hope it helped!
~Crockeo
This post has been edited by Crockeo: 07 April 2012 - 05:08 AM
#4
Re: Overloading and Overriding methods in classes
Posted 07 April 2012 - 04:46 PM
Let's combined them 

class Animal { void makeNoise() { makeNoise("noise"); } void makeNoise(String str) { System.out.println(str); } } class Dog extends Animal { void makeNoise() { makeNoise("bark"); } } class Cat extends Animal { void makeNoise() { makeNoise("miaou"); } }
#5
Re: Overloading and Overriding methods in classes
Posted 07 April 2012 - 07:48 PM
Wooh! Teamwork!
#6
Re: Overloading and Overriding methods in classes
Posted 07 April 2012 - 08:11 PM
Page 1 of 1