473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Private Interface example

21
Just thought of posting this example about private interface which i learned from bruce eckel book "Thinking in Java"

An interface can be nested within a class or another interface. If the interface is nested within a class it can be public or private. But if a interface is nested within a interface it should be public which is by rule.

I was wondering what will be the use of private interface within a class. Then came up with this design.

class librarian {

private interface libraryRules{
void takeHome();
}

public class book implements libraryRules{
private book() {}
public void takeHome(){
System.out.println("takeHome this book");
}
}
public static libraryRules getPermission(librarian ob1){
libraryRules obj = ob1.new book();
return obj;
}

public void gotPermission(libraryRules tmp) {
tmp.takeHome();
}
}

public class library{
public static void main (String arg[]){
librarian obj = new librarian();
obj.gotPermission(librarian.getPermission(obj));
}
}
Dec 1 '07 #1
0 4700

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Dave | last post by:
Hello all, Suppose that derived inherits privately from base. A base pointer may not be made to point at a derived object in this case. I understand that is exactly what is supposed to happen...
19
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
12
by: Manolis | last post by:
Hi, I was wondering if there is any way to make two objects of the same class to be able to access each other's private data, like this: class A { public: void access( const A& a )...
0
by: news_mail_jpa | last post by:
Hi! I'd like to implement a private interface and I have the choices mentioned in the subject. The implementation using private inheritance is probably cleaner but it also adds some space and...
7
by: Charles Law | last post by:
Sorry, but I am on a bit of a roll today. I have just found that I can make a method private to my class, but then use AddHandler in an external class to hook it up. Is that what people would...
6
by: WXS | last post by:
I know this sounds contrary to the idea of an interface, but read this and see what you think. ----------------------------------------------------------------------------------------- It would be...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
14
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
8
by: Ethan Kennerly | last post by:
Hello, There are a lot of Python mailing lists. I hope this is an appropriate one for a question on properties. I am relatively inexperienced user of Python. I came to it to prototype...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.