File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

protected constructor

 
neha. bajaj
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

J.java:4: error: I() has protected access in I
I obj=new I();
^
1 error

Then what is the use of protected access modifier for constructor ?
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It allows the constructor of a subclass to call it. For example with a super() call.
 
neha. bajaj
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:It allows the constructor of a subclass to call it. For example with a super() call.

Could you give me an example ?
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package pkg;
public class I{
protected I(){
System.out.println("I()");
}
}
import pkg.I;
class J extends I
{
public J()
{
super();
System.out.println("J()");
}
}
 
neha. bajaj
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J extends I and I() is protected constructor why it won't be available in class J while protected class members of I() are available.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
neha. bajaj wrote:
Matthew Brown wrote:It allows the constructor of a subclass to call it. For example with a super() call.

Could you give me an example ?


Wasn't that an example?

Henry
 
neha. bajaj
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
neha. bajaj wrote:
Matthew Brown wrote:It allows the constructor of a subclass to call it. For example with a super() call.

Could you give me an example ?


Wasn't that an example?

Henry


Sorry i was writing that post while he has been edited his post.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic