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



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. what items do i add?
View Tutorial          By: Camo at 2015-09-30 23:02:10

2. Very nice article. Really liked the way it took me
View Tutorial          By: Sandeep at 2010-01-10 09:58:25

3. VERY good info. Providing By YOU Thanx.
View Tutorial          By: Ravi singh at 2013-11-14 08:56:34

4. It works like a charm. Thanks a lot.
View Tutorial          By: Balram at 2008-08-22 21:18:44

5. Do you happen to have the code of if statement for
View Tutorial          By: James at 2012-06-04 09:02:31

6. Thanks dear
View Tutorial          By: Muthin at 2009-04-29 00:32:24

7. Plz can someone help me, I copied the code above a
View Tutorial          By: Dse90 at 2010-02-10 04:28:34

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

9. Hello Ramlak, I am too getting
java.lang.U

View Tutorial          By: Amruta at 2008-11-07 23:56:17

10. can you help me do this? - write a program that wi
View Tutorial          By: rence at 2011-08-16 13:33:14