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. This is an old method although it works. The bette
View Tutorial          By: Emiley at 2013-01-11 03:56:02

2. Good morning!
I need help about how to conf

View Tutorial          By: alpha at 2009-06-14 03:20:41

3. The textarea value(finalresult) i want save in Tre
View Tutorial          By: anbalagan.s at 2007-10-17 05:10:19

4. super
View Tutorial          By: asasdfsa at 2014-05-29 05:23:04

5. Hi Friends.... This code is working correctly with
View Tutorial          By: kasi at 2009-11-25 23:52:56

6. Thanks, how about using isset() function on page/U
View Tutorial          By: Paolo at 2009-06-01 07:29:10

7. thanks
View Tutorial          By: nitin at 2010-03-29 01:02:57

8. This article is very good. It is very easy to unde
View Tutorial          By: Vandana B.Dass at 2010-02-01 00:54:54

9. I tried ....so this is best solution for understa
View Tutorial          By: rehnuma at 2015-03-30 12:29:38

10. Nice info. I must say about this post.
than

View Tutorial          By: Ganesh Prasad at 2012-10-30 05:51:49