cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt in Inheritence

Former Member
0 Kudos

What will happen when you attempt to compile and run this code ?

class Base{

public final void amethod()

{

System.out.println("amethod");

}

}

public class Fin extends base{

public static void main(String argv[])

{

Base b = new base();

b.amethod();

}

}

Accepted Solutions (1)

Accepted Solutions (1)

sridhar_k2
Active Contributor
0 Kudos

Hi,

Output is : "amethod"

Inheritance is a major component of object-oriented programming. Inheritance will allow you to define a very general class, and then later define more specialized classes by simply adding some new details to the older more general class definition.

Search in Google, you can get so many answers.

For more your information please go thru the link.

http://www.phptr.com/articles/article.asp?p=26430&rl=1

Regards,

Sridhar

Answers (2)

Answers (2)

Former Member
0 Kudos

Only one rule that we need to remember while using final keyword.ie

It cannot be inherited in case of class and it cannot be over rided in case of method.

So in this case your out put will be <b>amethod</b>

Former Member
0 Kudos

Hi

The output will be "amethod"

Kind Regards

Mukesh