cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt in abstract class and inheritence

Former Member
0 Kudos

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

class Base{

abstract public void myfunc();

public void another()

{

System.out.println("Another method");

}

}

public class Abs extends Base

{

public static void main(String argv[])

{

Abs a=new Abs();

a.amethod();

}

public void myfunc()

{

System.out.println("My func");

}

public void amethod()

{

myfunc();

}

}

Accepted Solutions (1)

Accepted Solutions (1)

sridhar_k2
Active Contributor
0 Kudos

Hi Dipendra,

You seems to be very new to Java. I advice you to go thru the java basics from the below site.

One more thing, before posting just execute the java application in your NWDS in java perspective.

See this link for information about abstract and inheritance class:

http://www.particle.kth.se/~lindsey/JavaCourse/Book

www.java.sun.com

www.onjava.com

Regards,

Sridahr

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You will get a compilation error since your class Base is not an abstract but has an abstract method.

Once you change your declaration

from "class Base" to "abstract class Base"

you should get a prinitng of "My func" when you run the main method

Btw, by simply launching it or making attempt to compile you can see what exactly is being printed, which seems to be much more efficient than flooding the forum with questions. Unless of course you are in some kind of job interview and you are taking a java exam ...

HTH

Peter