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. I'm working on an intranet site/web application. W
View Tutorial          By: Tony Gingrich at 2011-10-23 21:22:31

2. Thanks for the tutorial.

One questi

View Tutorial          By: Stephen at 2012-06-09 06:36:23

3. it is very good website for IT students
View Tutorial          By: jeecee at 2013-03-21 12:23:46

4. I have maked all you said and when I open jsp I am
View Tutorial          By: ismail at 2011-03-16 04:08:53

5. i m new in java plz send package of simple program
View Tutorial          By: iqbal ahmad at 2009-09-07 01:26:41

6. I need dumps for practice
View Tutorial          By: Sanket barge at 2011-06-17 10:05:16

7. Thanks for the useful tutorials abt strtus 1 vs St
View Tutorial          By: Sudharsan at 2011-12-03 11:54:58

8. Can you please send me the full code in sending an
View Tutorial          By: jen at 2008-05-28 00:22:21

9. You have to run the compiled PortScanner with two
View Tutorial          By: KRook at 2009-10-15 04:11:53

10. Awesome work! Ramlak, thank you for your help!
View Tutorial          By: ico at 2011-03-21 04:23:11