FAQ Database Discussion Community


changing of private variables

java,private
Since a few months I'm having a Java course and I'm trying to make a simple version of a pokemon game. Until now everything went pretty well but now I'm having troubles. I have my map with obstacles stored in a class in an Array (private) and use a get...

abstract private inner class

java,abstract-class,private,inner-classes
I am preparing for an Oracle examination and answered incorrectly to the following question: the combination abstract private is legal for inner classes As it turns the answer is true, I answered false, as I could not find any use cases for having an abstract private inner class, that cannot...

Can't call a public method c# [closed]

c#,class,methods,private,public
namespace ConsoleApplication3 { public class EncapulationTest { public static void publicMethod() { Console.WriteLine("This is the public method from the EncapsulationTest class!"); } private static void privateMethod() { Console.WriteLine("This is the private method from the EncapsulationTest class!"); } } public class Main { public static void Main() { publicMethod(); Console.ReadLine(); }...

How can I write this private method for being unique to the ticket number, and set that ticket number constructor?

methods,constructor,private
ParkingTicket Here are the relevant attributes: ticket number of type String the name of the police officer who issued the ticket the police officer's badge number the car's license number the car's make the car's model amount of the fine Note that the ticket number must be unique, created by...

How to access dynamic array inside a class constructor?

c++,arrays,class,private
How do I access the dynamic array and set values to it? For example array[size] = {8, 4, 3, 2, ...} class Array { public: Array(int sze)// default constructor { size = sze; ptr = new int [size]; } private: int size; // number of elements in the Array int...

returning reference to private vs public member

c++,qt,reference,private,public
I would like to know what could be reasons to provide a public access method returning a reference instead of making the member public. QPoint has methods int& rxand int& ry that let me directly manipulate the coordinates. I guess the implentation looks similar to this: public: int& rx(){return x;}...

Plotly with R ggplot

r,ggplot2,private,plotly
I'm plotting a graph with ggplot, using plotly. How do I make the plot private rather than public on plotly? My code looks like: a <- ggplot(data, aes(var1, var2, text=var3)) + geom_point() py$ggplotly(a) ...

how variables declared private in javabean get accessed by jsp

java,private
I have defined many private variables and also defined there getter/setter method and then I'm accessing these variables in jsp page by using expression language.But how privately defined variables gets accessed in jsp page?? My java bean code is- The variables are private String beam_current; private String beam_energy; private String...

Implementing: private structs in Class

c++,struct,iterator,private
I have a List class which uses two objects: Element & Iterator I considered making Element & Iterator classes but decided on structs. V1. This works... template <class T> struct Element template <class T> struct Iterator template <typename T> class List { public: typedef Iterator<T> iterator; private: }; Which allows...

Documenting public methods on private structs via Godoc in Go

go,private,godoc
I have a private struct (actually more than one, I simplified a bit for this example) which I have a public function on, that satisfies a public interface. This struct is created via a factory method (NewX-style): package godocprivate type PublicInterface interface { PublicFunction() } type privatestruct struct { }...

Java prevent calling private or protected methods outside of class

java,reflection,private
Let's supppose that I have created a Java library, called Foo and I have a class inside that library called Bar. Let's suppose further that in the Bar class I have a private method, called fooBar. public class Bar { //... private Object fooBar() { //Do something } //... }...

Why this private method does get executed from another class?

c#,private
I Created and implemented an interface explicitly as below. public interface IA { void Print(); } public class C : IA { void IA.Print() { Console.WriteLine("Print method invoked"); } } and Then executed following Main method public class Program { public static void Main() { IA c = new C();...

C++ Isn't this a useless inline declaration?

c++,inline,private,member,protected
This is another question about inlining a function. But I will take possible comments and answers right away: Defining a function inside a class makes it inline automatically. The same behaviour can be achieved by marking a function with inline outside of the class. An inline function doesn't have to...

Accessing private C++ methods within C++/CLI wrapper

c++,c++-cli,private
Given a class method in C++ that has to be private there, how to make C++/CLI access it. Example: C++ class has a private constructor that shouldn't be exposed to the external user, C++/CLI managed code has to have similar private constructor, but internally it must access private C++ constructor...

Copy constructor in private class Syntax

c++,private,copy-constructor
in 2 hours I'll take an exam on C++ and I'm still wondering about the syntax of the copy constructor. So far what I understand is that you put the CopyConstructor in private so that when some function or whatever wants to copy your class it is not going to...

Can I run multiple private docker registry behind load balancer?

load,load-balancing,private,multiple-instances,docker-registry
I was wondering if it's possible to run multiple docker registry hosts under an ELB or (any load balancer for that matter). I am planning to run the private docker registry inside a docker container. Has anyone tried that? Any ideas for how to have Docker registry containers autoheal without...

PHP: Get list of private fields of a class (not instance!)

php,field,private
How can I iterate the private fields of a class without having an instance of it but just the class name? get_object_vars requires an existing instance.

How can a class method access a private member of another instance of the same class?

java,private
I cannot understand the code in jdk1.7. value is private, so why can the code use it with e.g. anotherString.value? public final class String implements java.io.Serializable, Comparable<String>, CharSequence { /** The value is used for character storage. */ private final char value[]; /** Cache the hash code for the string...

setting public property in a private function executed on initialization Javascript

javascript,constructor,private,public
I have an object with myObj = function(){ this.myPublicMember = null; function privateInitFunc(){ this.myPublicMember = "blah blah test"; } privateInitFunc() } myObj.prototype = { getPublicMember: function(){ console.log(this.myPublicMember) } } and I instantiate like: var a = new myObj(); a.getPublicMember // logs Null! How do I set a public property in...

In immutable class why fields are marked as private?

java,oop,field,private,immutability
What is the benefit of making fields private while creating an immutable class? I have seen why while creating immutable class, fields are declared as private? but I didn't get understand anything from this post. Can anybody please explain me the same?...

How Do I Make Private Variables Inaccessable in Python? [duplicate]

python,class,oop,object,private
This question already has an answer here: Does Python have “private” variables in classes? 8 answers class Car(object): def __init__(self, color, engine, oil): self.color = color self.__engine = engine self.__oil = oil a = Car('black', 'a cool engine', 'some cool oil') We assume that __engine and __oil variables are...

Why can a private class method be explicitly invoked in Ruby?

ruby,private
As we know, the private methods cannot be called with an explicit receiver in ruby. But when I define a class, I can invoke a private class method by the class itself. For example: class A private def self.test puts "hello,world!" end end A.test => hello,world! A.new.test NoMethodError: private method...

Access modifiers in C#

c#,private,access-modifiers
I am teaching myself C# and I have run into a bit of an ambiguous situation. What I'm trying to do is create a container class for some data, fairly straight forward but I am trying to respect encapsulation and have the data accessible via setters and getters only. So...

Using private class in Android

android,class,static,private
Hi I have a question about using private class in Android activities. Let's say I have a simple listView in an activity. I want to define an adapter class for this listView(which extends BaseAdapter). Since the adapter is pretty simple, I want to define a private class in this Activity...

Java 9: private interface methods, example use-case?

java,interface,private
"Support for private methods in interfaces was briefly in consideration for inclusion in Java SE 8 as part of the effort to add support for Lambda Expressions, but was withdrawn to enable better focus on higher priority tasks for Java SE 8. It is now proposed that support for private...

(Java) modifying public static variables

java,constructor,static,private,public
kinda new here. Anyways, I'm relatively new to Java, this is some practice questions from uni, I have one question. How do I make it so that TOTAL_RESERVES can't be modified by an outside. Right now if I say Gold.TOTAL_RESERVES = 500; That changes the value of it. How do...

Definition of function which is the class member

c++,function,class,private,member
I have two functions, which are private members of class "Data": class Date { private: bool leapYear(int y); void fillDate(int d, Month m, int y); }; So, where is the best to define this functions: in class definition; in header file outside the class; or in ".cpp" file? ...

.valueOf using another class's private variable

java,class,private,tostring,value-of
BaseExample Class (I am not allowed to make the variable protected on this example): public class BaseExample { private int a; public BaseExample(int inVal) { a = inVal; } public BaseExample(BaseExample other){ a = other.a; } public String toString(){ return String.valueOf(a); } } DerivedExample Class: public class DerivedExample extends BaseExample...

Initializing a private static member variable in the cpp file. error: member is private

c++,static,initialization,private
Here is a simple example illustrating my problem. IDGenerator.hpp #ifndef IDGENERATOR_HPP_ #define IDGENERATOR_HPP_ class IDGenerator { private: static int s_nNextID; // make the IDGenerator class a static class with a private default constructor IDGenerator(); public: static int GetNextID(); }; #endif IDGenerator.cpp #include "IDGenerator.hpp" // initialize the static id int IDGenerator::s_nNextID(1);...

C++ turn public a variable after private extending

c++,inheritance,private
The doubt is as the title states: With a class as follow: class A { public: int a; int b; int c; function1(); function2(); } and a class B extending A, how to turn public all variables from A? class B : private A { public: int a; //How to...

Accessing parameters of the same name of different classes in Scala

scala,private,public
I have a very specific scenario, in which I have some different abstract classes the have child case classes that can have different parameters, for example: abstract class ball() {} case class football(_name: String, _shape: String) extends ball case class basketball(_name: String, _size: Int) extends ball and a different abstract...

Exit Back Out of Private NPM Repo

node.js,npm,private,exit,repo
So... I know this is probably a stupid question but I can't seem to find the info anywhere and I figure I can't be the first to ask.. I have been using my companies internally hosted NPM Repo for so long I've forgotten how to get OUT of it and...

Object-Oriented programming private class field + get / set or public class field?

java,oop,private,public
I'm a junior developer (currently exercise Java) and I have one question about the correctness of my code, here is an example: I am writing a simple MMO-game representation on Java, I have 2 classes (Character and spell). Character has properties (mName, mHealth and mEnergy), Spell class has properties (mSpellName,...

Is there a way to protect a class variable from being modified outside of a function

c#,class,private,friend
I have a volume variable that I want to be protected from modification unless the person calls a certain function. Is there a way to make it to where it can only be modified by that function other than creating a private class within the class. I suppose that creating...

why public methods are there in object class?they can be protected and will keep thing more private

java,private,public,protected,access-specifier
As for java architecture is concern "to keep things as much private as possible".Thats why finalize method is protected in object class. protected void finalize() throws Throwable { } Why is the finalize() method in java.lang.Object “protected”?please have a look on Mehrdad Afshari answer. then why many other method like...

c++ class: using a private array in a public function?

c++,arrays,class,private,public
Here's the code I'm working with in the header file: #ifndef TETRIS_TETRIMINO #define TETRIS_TETRIMINO const int TETRIMINO_GRID_SIZE = 4; struct Location { int row; int col; }; class Tetrimino { private: int grid[TETRIMINO_GRID_SIZE][TETRIMINO_GRID_SIZE]; char color; Location location; public: // constructor Tetrimino(int type = 7); // valid type values are 0-6...

How to override private method from a library class

php,override,private
Given are the following classes with class A coming from an external library so that I can not change it: class A { public function test () { $this->privateMethod(); } private function privateMethod () { echo('A'); } } class B extends A { private function privateMethod () { echo('B'); }...

Needing a private and public method for the same recursive function

c++,recursion,methods,private,public
We have recently been working on implementing recursive methods for several classes (trees, heaps, queues, linked lists, etc) in C++ for my computer science class. I have not been having any trouble writing the implementations for the methods, but something my professor mentioned briefly in passing confused me and she...

Can't access private variable from own class via subclass instance

java,private
class A { private int foo; void bar(B b) { b.foo = 42; } } class B extends A { } This fails to compile with the error: A.java:3: error: foo has private access in A void bar(B b) { b.foo = 42; } ^ 1 error Adding a cast...

Objective-C public get set method for private property

objective-c,properties,private,synthesize
I wonder if it is possible to use @synthesize on a private @property so that the get/set methods have public access. Right now my code looks something like this SomeClass.h #import <Foundation/Foundation.h> @interface SomeClass : NSObject { @private int somePrivateVariable; } @end SomeClass.m #import "SomeClass.h" @interface SomeClass () @property int...

where the behavior of private and static method is different from only private method

java,static,private,access-specifier
As for my understanding: When a method is static it is early bind can call with the name of class even before no object is created can call only static member inside it. I never found any other behaviour of static either at compile time or runtime. Is there any?...

c++ private static member variables compared to free nonmember

c++,private,member
I'm relative new to C++ and have a question regarding private static member or "free nonmeber". I can write my code like this: // MyClass.h - Version 1 class MyClass { public: MyClass(); ~MyClass(); private: static int iValue; }; // MyClass.cpp int MyClass::iValue = 123; The other way without...

I don't understand private variables?

java,private
There is nothing wrong with the code, but I don't understand why you have to create a private String name, and then equals that string with the string from method i.e. name = n. public class Person { private String name; public Person (String n) { name = n; }...

How is it that I am able to reference private fields of an instance inside a class?

java,private
I have had a look for an explanation but haven't been able to find one. Why does this code work? Specifically - why can the private members of an instance be accessed? As far as I know it only works when the instance is created in a method inside the...

Read-only attributes via properties versus via documentation

python,properties,attributes,private,readonly
In Python I'm writing a class where some attributes must remain constant during the object lifetime. One way is to use properties: class Foo: def __init__(self, x, y): '''Create a Foo object x -- list of int (READ-ONLY) y -- float ''' # Save x and y and ensure they...

Access private data type in base class if only private function exist

c++,inheritance,private
Given the code below, we can access private data of base class if the function in base are protected by using inheritance. My question is, is there any way we can access private data if all methods in base class are also set to private? class Base { int i;...