This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes regarding abstract Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regarding abstract" Watch "regarding abstract" New topic

regarding abstract

rajesh ssh

Joined: Aug 23, 2006
Posts: 11
public abstract class Test
private int i=900;

public class TestChild {

public void method()
System.out.println(i);//here 'i' can access like wise
// if i have private abstract void method in the Test then that also by extending i can implement it ..?


// My Query is if Test class has private abstract void method(); then the inner class by extending that can implement body to that right ?
[ April 30, 2008: Message edited by: rajesh ssh ]

Regards<br />RAJESH.M
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265


Per the Java Language Specification, it's a compile time error for a private method to be declared abstract.

It's impossible for a subclass to override a private method, because private methods are not inherited by subclasses.

As a side note, please post your code within the UBB Code tags for readability. Thanks!
[ April 30, 2008: Message edited by: Stevi Deter ]

There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
rajesh ssh

Joined: Aug 23, 2006
Posts: 11
hi,coulu you please tell
public class Test { private int i=900; private void method() { return; } public class TestChild extends Test { public void method1() { super.method(); } } } }

here private method can access in the sub class TestChild also..right ?
rajesh ssh

Joined: Aug 23, 2006
Posts: 11
yes,you are correct i understand in the last post i just called the method but i have not overriden.we cannot override private methods ,
Thank you
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
You have declared a child class as inner class.As per JAVA ,inner class has no self existence ,it's scope is limited to the declared class.Therefore it can access private(public ,protected) members of outer class.Just check the class file name of this will be like "Parent$Child.class" ,separated by "$".

About "private abstract retrunType someMethod()" , already good explanation posted above.I would like to add only that in my opinion "private" and "abstract" is contradictory.Private is just to hide something and abstract give you the facility to someone to write on implementation(to exhibit).There language of creator did not allow us to write "private abstract" simultaneosly.
I agree. Here's the link:
subject: regarding abstract
It's not a secret anymore!