Questions tagged [public-method]

A public method is a method declaration that allows access from other classes external to the current class.

A public method is a method declaration that allows access from other classes external to the current class. Public methods are used in many Object-Oriented programming languages including Java, C#, and Objective-C

From http://www.javabeginner.com/learn-java/introduction-to-java-access-modifiers

Fields, methods and constructors declared public (least restrictive) within a public class are visible to any class in the Java program, whether these classes are in the same package or in another package.

184 questions
6
votes
1 answer

Why do PHP magical methods have to be public?

I use magical methods in my PHP classes but when i try to put them private, I'm warned : WARN: The magic method __get() must have public visibility and cannot be static in ... I wouldn't like to have these methods in Eclipse auto completion.…
TeChn4K
  • 2,317
  • 2
  • 21
  • 23
6
votes
0 answers

how do I protect a public API from abuse?

Given a public API which triggers OTP verification to users, is there a way to prevent such an API from abuse/spam? This API is public and have business reasons so offering on public side. API is developed using Java Spring MVC and has CORS enabled…
suman j
  • 6,710
  • 11
  • 58
  • 109
6
votes
1 answer

c++ how to create public and protected accessors to same member

In case I have two methods - one public, one protected that return the reference to same member, I get following compilation error: 'Server::getManager': cannot access protected member declared in class 'Server' When I comment out protected…
Zheden
  • 583
  • 2
  • 11
  • 36
6
votes
4 answers

Calling a public method on windows service

I have a timer in a windows service (.NET C#). I need to be able to change the elapsed value from an external program. If the timer is currently running, I need to be able to shorten the time elapsed value from an external program. I was…
Prabhu
  • 12,995
  • 33
  • 127
  • 210
5
votes
1 answer

Programmatically check if method is public

Possible Duplicate: How to check if a function is public or protected in PHP Is there a function that checks if giver method of given class is public? I know method_exists(), but it does not work how I want to. If there isn't how can I check…
Nikolay
  • 89
  • 1
  • 3
5
votes
4 answers

Scala public methods: ';' expected but 'def' found

I wrote this method: public def getXScaleFactor(panelWidth: Int): Double = { return (panelWidth / (samplesContainer[0].length.asInstanceOf[Double])) } and I have problems with compilation: [error]…
ciembor
  • 7,189
  • 13
  • 59
  • 100
5
votes
4 answers

why there are public methods in the Object class in java?

When we know that in java all classes by default extends Object class, so why there are methods with public modifier where as protected would suffice the accessing of these methods from any class? So need some info on this. thanks.
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
5
votes
7 answers

When should you use public static methods

There are a lot of people out there against the use of "public/private" static methods. I have search around,with no luck, and tried to find anyone that advocates good use of static methods. Assuming the methods will always be Cohesive where are…
Nix
  • 57,072
  • 29
  • 149
  • 198
4
votes
2 answers

Private parameters in public methods

Neither g++ nor javac emit warnings when the parameters to non-private methods are of private types (e.g., private nested classes). Such methods cannot be used by clients, but they can appear as part of a class's public API. In C++, putting such…
ManRow
  • 1,563
  • 4
  • 21
  • 40
4
votes
2 answers

Find out whether a method is protected or public

With this code I'm trying to test if I can call certain functions if (method_exists($this, $method)) $this->$method(); however now I want to be able to restrict the execution if the $method is protected, what would I need to do?
Moak
  • 12,596
  • 27
  • 111
  • 166
4
votes
1 answer

Why is my top-level method public (as opposed to private) on all classes when I declare it in IRB?

I'm currently reading "The Well-Grounded Rubyist", and on page 196 I see the following: Suppose you define a method at the top level: def talk puts "Hello" end .... A method that you define at the top level is stored as a private instance…
Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
4
votes
1 answer

Which Delphi version supports RTTI for public methods?

By default, RTTI in versions below 2010 is only created for published class members. I have read in a 2006 blog (http://hallvards.blogspot.com/2006/09/extended-class-rtti.html) that using $METHODINFO (or $M), public and published methods are…
mjn
  • 36,362
  • 28
  • 176
  • 378
4
votes
2 answers

Private methods are appearing as public methods

I am trying to improve the design of my App by using private methods. Coming from .NET I am a little confused because I am declaring these methods in the .m file but from other files they are still showing up i.e. they are still accessible. .m…
TheLearner
  • 19,387
  • 35
  • 95
  • 163
4
votes
3 answers

JavaScript: Public methods and prototypes

I'm not entirely sure how to implement OOP concepts in JS. I have a class which is entirely declared in its constructor: function AjaxList(settings) { // all these vars are of dubious necessity... could probably just use `settings` directly …
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
4
votes
2 answers

How do I call a non-public method of a public class in Clojure?

I'm calling the twitter4j library using Clojure like so: (def twitter (. (TwitterFactory.) getInstance)) This works fine when I call it as a script. But when I use gen-class, I get: java.lang.IllegalArgumentException: Can't call public method of…
sramsay
  • 43
  • 3
1 2
3
12 13