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. your second last example in above code (Character
View Tutorial          By: rupam shaw at 2013-04-24 08:36:05

2. Thanks!
View Tutorial          By: misterTi at 2015-03-18 17:48:41

3. Excellent explanation...Thanku.
View Tutorial          By: Rajpal Singh at 2012-12-29 05:36:20

4. really a big salute for this notes
View Tutorial          By: SUNDARARAJ VELUSAMY at 2010-09-14 23:39:48

5. the discussion is not enogh
View Tutorial          By: gulstan at 2011-03-27 03:47:24

6. good example
View Tutorial          By: WANT TO KNOW WHY WE USE APPEND at 2011-06-14 00:39:48

7. HOW TO SET PASSWORD IN JAVA.....
View Tutorial          By: NAKUL at 2012-12-14 05:23:16

8. i m happy this programs thsk
View Tutorial          By: jai at 2011-05-09 14:20:35

9. Nice article, Thank you
View Tutorial          By: kumar kasimala at 2010-04-26 21:09:25

10. Please don't give example from book this example i
View Tutorial          By: aniruddha at 2011-03-23 00:34:32