File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract Class" Watch "Abstract Class" New topic
Author

Abstract Class

Divya Dronamraju
Greenhorn

Joined: Jan 07, 2008
Posts: 5
Can "protected" be used in the declaration of an abstract method in an abstract class?
Kaywin Dcosta
Greenhorn

Joined: Jan 19, 2008
Posts: 4
protected methods are possible inside abstract class

//class AbstractTest
public abstract class AbstractTest {
private void test() {
System.out.println("Inside test private");
}
protected void test1() {
System.out.println("Inside test protected");
}
void test2() {
System.out.println("Inside test default");
}
public void test3() {
System.out.println("Inside test public");
}
}

//class AbstractImpl

public class AbstractImpl extends AbstractTest {
public static void main(String[] args) {
AbstractImpl ob = new AbstractImpl();
// ob.test();//not possible to instansiate abstract classes
ob.test1();
ob.test2();
ob.test3();
}
}
Srinivas Kollaparthi
Greenhorn

Joined: Jan 19, 2008
Posts: 11
For an abstract method, only public or protected modifiers can be set.
If this abstract class is extended by another class of different package then that class should able to access this abstract method to override.

Only public, protected members can be visible to all its subclasses in any packages.

We can also leave a abstract method declaration with default access.
But the problem arises when it is extended by a class of other package.
In that case, that second class cannot implement this abstract method as the method is not visible to other packages. The only solution to this make the second class type abstract as below.

package com.nanna.abs.one;

public abstract class AbstTest {

abstract void test();

}

package com.nanna.abs.two;

import com.nanna.abs.one.AbstTest;

public abstract class TestOnAbstract extends AbstTest{


public void test2(){


}

}


We can conclude that chain of subclasses of AbstTest cannot be instantiated as they must declare abstract.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Abstract Class