• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding abstract

 
rajesh ssh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh,

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 ]
 
rajesh ssh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 class.it 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic