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. It is clear but at the starting code there is a wr
View Tutorial          By: Kiranmoy Pradhan at 2015-08-20 21:55:15

2. i want ask whether how do i run the application?
View Tutorial          By: unknown at 2009-10-29 21:13:03

3. I am using MacOSX 10.5.4 and only enabling the mod
View Tutorial          By: Sachin at 2011-03-26 00:23:05

4. Hi sir,
please send some sample code for sp

View Tutorial          By: Kruttika at 2015-07-07 05:14:14

5. Actually in gallery example the images can be move
View Tutorial          By: santu at 2013-02-16 12:40:29

6. Ho,i have created read and write program on differ
View Tutorial          By: niranjan at 2015-08-26 09:02:57

7. how to refresh the radiobuttons during the run tim
View Tutorial          By: Vishnupriya at 2009-02-04 03:25:24

8. java program to maintain the books details like Bo
View Tutorial          By: Prabha at 2013-08-28 12:34:00

9. Hi to All,
I am working on struts based apl

View Tutorial          By: Ishmayel at 2009-02-19 21:27:14

10. @ parul : check whether your are passing class fil
View Tutorial          By: heramb at 2012-03-28 07:15:21