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. Can you please give the driver class for this code
View Tutorial          By: ani at 2012-09-20 17:23:13

2. hai
View Tutorial          By: ayyannan at 2011-01-21 21:27:35

3. Hi, thanks alot this code works for me , can someo
View Tutorial          By: ann at 2011-03-18 04:50:16

4. Excelente, y a pesar de que mi inglés no es
View Tutorial          By: Monica at 2009-03-24 13:53:51

5. package com.anand;

import java.sql.

View Tutorial          By: Anand at 2012-11-12 00:00:07

6. MSComm1.Settings="9600,n,8,1"

View Tutorial          By: ali at 2012-02-25 21:52:21

7. What is this....for simple question every one was
View Tutorial          By: Kaify at 2011-07-27 21:35:52

8. what ll be result for s1==s2 and s1.equals(s2) for
View Tutorial          By: vijay at 2011-08-21 15:09:41

9. Thanks!
View Tutorial          By: misterTi at 2015-03-18 17:48:41

10. very nice content
View Tutorial          By: jagadeesh at 2012-04-25 06:24:03