cancel
Showing results for 
Search instead for 
Did you mean: 

doubt in abstract class

Former Member
0 Kudos

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

abstract 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 (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Please see the basic rules for abstract class.

1) All the abstract methods should be over rided in inherited classes.

2)If one method in a class is abstract, that class as whole is marked as abstract.

3) An abstract class can contain both constructive (another() in this example) and abstract methods.

So out put will be <b>My Func</b>.

Is it clear?

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Dependra,

You dont have java compiler? above code giving

output:My Func

See this link for information about abstart class:<a href="http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter04/abstract.html">Here</a>

For inheritance:<a href="http://www.holtsoft.com/java/resources/inherit_tutorial/Inheritance/Inheritance.html">Here</a>

You can search for java documents in net

best site is

1. www.java.sun.com

2. www.onjava.com

Regards

Suresh