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. dear sir, plz answer my following questions:

View Tutorial          By: hawa at 2012-01-29 08:29:39

2. please give example code with defined variable.
View Tutorial          By: shajjad at 2011-02-13 20:56:09

3. I get theses errors and apparrently it cannot find
View Tutorial          By: Abhaya at 2013-02-20 22:42:18

4. my program is run and it created file in the sd ca
View Tutorial          By: mahesh at 2013-01-21 04:15:21

5. Thanks for providing this page it works with local
View Tutorial          By: Dharam Jaswal at 2012-02-02 13:19:24

6. Best Example for Inheritance. Thank lot!

View Tutorial          By: Periyasamy C Chennai at 2010-07-09 01:35:30

7. Very Easy To Understand
View Tutorial          By: Najeeb at 2011-06-09 04:12:34

8. I really thanks to you for providing wonderful inf
View Tutorial          By: Chandra Sekhar Puli at 2009-11-07 04:03:44

9. Great Help...
View Tutorial          By: adity at 2012-04-27 05:34:26

10. So, is it possible to use the getClass() and getRe
View Tutorial          By: cee at 2014-11-29 14:27:10