Abstract Class or Method


Question:
Can we make use of "this" keyword reference inside a abstract method or Abstract Method?
Answer:
Yes You Can do that
For Example:
public abstract class TestExample{

private String exampleid;

private String examplename;

public TestExample(String exampleid ,String examplename)

{

this.exampleid= exampleid;

this.examplename= examplename;

}

//public gettors and settors

public abstract void scheduleTest();

}


public class JavaTestExample extends TestExample

{

private String typeName;

public JavaTestExample(String exampleid, String examplename, String typeName)

{

super(exampleid, examplename);

this.typeName =typeName;

}

public void scheduleTest()

{

//do Stuff

}

}



A class has a constructor so that when an instance of the Class is created
the fields of the class can be setup to a initial valid state.

Abstract classes define partial implementation of a public contract. Which
means that it may implement some of the methods and contains partially
implemented methods that are marked abstract.

Since abstract classes can have partial implementation and such partial
implementation can include fields of the class a constructor becomes necessary
so that those fields are initialized to a valid default state when they are
created thru the constructor of their concrete subclasses.

All abstract class are not pure abstract partially they are. So if you
need a pure abstract class go for an Interface.

No comments:

Post a Comment

Please Provide your feedback here