Comment on Tutorial - Method Overriding in Java By Henry



Comment Added by : pratham

Comment Added at : 2010-09-22 10:10:11

Comment on Tutorial : Method Overriding in Java By Henry
If i run this program----


// Methods with differing type signatures are overloaded – not
// overridden.
class A {
int i, j;
A(int a, int b) {
i = a;
j = b;
}
// display i and j
void show() {
System.out.println("i and j: " + i + " " + j);
}
}

// Create a subclass by extending class A.
class B extends A {
int k;
B(int a, int b, int c) {
super(a, b);
k = c;
}
// overload show()
void show(String msg) {
System.out.println(msg + k);
}
}

class Override {
public static void main(String args[]) {
B subOb = new B(1, 2, 3);
subOb.show("This is k: "); // this calls show() in B
subOb.show(); // this calls show() in A
}
}
THERE IS RUNTIME ERROR

Exception in thread "main" java.lang.NoSuchMethodError: main


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Hi this is very clear and helpful, I would like to
View Tutorial          By: JoelC at 2012-11-06 16:23:19

2. I don't think GSM/Modem simulatur, will get it wor
View Tutorial          By: Michael Chon at 2008-10-08 10:35:55

3. You should add the mime type as follows:

View Tutorial          By: Anonymous at 2009-03-19 08:30:35

4. It tried this app... It's working fine... really a
View Tutorial          By: Prakash at 2012-01-04 06:33:12

5. thanks a lot dude,my lecturer took 2 weeks to expl
View Tutorial          By: praveen malinga at 2010-02-25 07:53:01

6. This is very helpfull to us.........thnq
View Tutorial          By: lavanya at 2012-03-17 05:43:12

7. Thank you......
View Tutorial          By: Suvadip at 2013-04-19 05:11:51

8. The example given here are simple and easy to run
View Tutorial          By: Kranti at 2012-04-26 10:18:34

9. Hi,
I can run this program.But after

View Tutorial          By: jayaraj at 2009-06-05 01:28:18

10. The sample code was all I needed to figure out how
View Tutorial          By: David at 2011-08-28 07:34:28