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. please add code snippets.
View Tutorial          By: jan at 2010-07-27 18:49:53

2. After a week of struggle, succeeded in sending mes
View Tutorial          By: Balaji G L at 2014-07-20 16:05:25

3. i appreciate the article for being straight to the
View Tutorial          By: shey-poun at 2011-12-14 06:39:51

4. it shows error
java.lang.NoClassDefFoundEr

View Tutorial          By: vamsi at 2010-05-14 23:09:03

5. Very nice tutorial........
View Tutorial          By: Santosh Saha at 2010-04-11 05:58:51

6. super explaination
View Tutorial          By: santhish at 2011-07-06 05:00:54

7. hie
can u plz tell how i maintain my rms f

View Tutorial          By: diya at 2010-04-30 01:38:06

8. Its Very Good Example
View Tutorial          By: Madhu at 2011-08-26 12:11:49

9. Hello sir pls send me
com.sun.speech.freett

View Tutorial          By: shanthi at 2013-03-22 11:18:56

10. Thanks for giving this basic example of Abstract c
View Tutorial          By: Yogendra Kirar at 2010-08-07 07:48:34