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. Hello,
Thank you very much for this sample

View Tutorial          By: Alex at 2010-08-12 07:30:32

2. First things first, you might want to use malloc(i
View Tutorial          By: leon at 2012-05-02 19:00:56

3. /*Overridding & equals:--> Overriding is an
View Tutorial          By: Naveen Kumar at 2011-04-30 18:44:55

4. very good exmpl and explantion
View Tutorial          By: harshita negi at 2013-10-16 02:19:35

5. Thanks for the help, however I am having some diff
View Tutorial          By: Andrew at 2008-09-30 14:51:14

6. it very usefull to introduse the j2me to me

View Tutorial          By: Sudhir at 2011-08-31 13:05:40

7. Thank you so much. You made my day. God bless you
View Tutorial          By: Gautam at 2012-09-18 16:24:19

8. finally an understandable example
View Tutorial          By: sdf at 2012-11-26 21:44:34

9. can anybody hp me how to create a rms database in
View Tutorial          By: contractornimesh at 2011-01-04 00:12:08

10. i need java simple programs
View Tutorial          By: Tharani at 2010-01-22 06:39:25