public

Why main method is marked as public?

℡╲_俬逩灬. 提交于 2019-11-27 04:39:22
问题 I have a question that why main method is marked as public ? According to an answer on stackoverflow, It is declared as static "The method is static because otherwise there would be ambiguity: which constructor should be called?" But, can anyone can explain why it is declared public always? 回答1: The initialization software that starts your program must be able to see main so that it can call it. 回答2: Because the JLS, Section 12.1.4, says so: The method main must be declared public, static,

C++: overriding public\\private inheritance

﹥>﹥吖頭↗ 提交于 2019-11-27 04:37:58
If B inherits from A using public , can B override one of the functions and force it to be private? class A { public: virtual double my_func1(int i); virtual double my_func2(int i); } class B : public A // Notice the public inheritance { public: virtual double my_func1(int i); private: virtual double my_func2(int i); } How about the other way around? if the inheritance type is private - can B force a specific function to be public? What if A is pure abstract? does it make a difference? Would protected make any difference in any combination? If B inherits from A using public, can B override one

Closest Ruby representation of a 'private static final' and 'public static final' class variable in Java?

淺唱寂寞╮ 提交于 2019-11-27 04:15:48
Given the Java code below, what's the closest you could represent these two static final variables in a Ruby class? And, is it possible in Ruby to distinguish between private static and public static variables as there is in Java? public class DeviceController { ... private static final Device myPrivateDevice = Device.getDevice("mydevice"); public static final Device myPublicDevice = Device.getDevice("mydevice"); ... public static void main(String args[]) { ... } } There really is no equivalent construct in Ruby. However, it looks like you are making one of the classic porting mistakes: you

Why does Typescript use the keyword “export” to make classes and interfaces public?

牧云@^-^@ 提交于 2019-11-27 04:14:08
问题 While dabbling with Typescript I realised my classes within modules (used as namespaces) were not available to other classes unless I wrote the export keyword before them, such as: module some.namespace.here { export class SomeClass{..} } So now I can use the above code like this: var someVar = new some.namespace.here.SomeClass(); However I was just wondering why this keyword is used opposed to just using the public keyword which is used at method level to signify that a method or property

Why use a public method in an internal class?

旧时模样 提交于 2019-11-27 04:09:21
问题 There is a lot of code in one of our projects that looks like this: internal static class Extensions { public static string AddFoo(this string s) { if (!string.IsNullOrEmpty(s)) return s + "Foo"; return "Foo"; } } Is there any explicit reason to do this other than "it is easier to make the type public later?" I suspect it only matters in very strange edge cases (reflection in Silverlight) or not at all. 回答1: UPDATE: This question was the subject of my blog in September 2014. Thanks for the

C# public variable as writeable inside the class but readonly outside the class

旧城冷巷雨未停 提交于 2019-11-27 03:01:55
问题 I have a .Net C# class where I need to make a variable public. I need to initialize this variable within a method (not within the constructor). However, I don't want the variable to be modifieable by other classes. Is this possible? 回答1: Don't use a field - use a property: class Foo { public string Bar { get; private set; } } In this example Foo.Bar is readable everywhere and writable only by members of Foo itself. As a side note, this example is using a C# feature introduced in version 3

Assign LAN IP address to Docker container different from host's IP address

梦想的初衷 提交于 2019-11-27 02:51:01
问题 Am not well versed with Unix networking, adding virtual interfaces etc, trying to learn it now. We are trying to dockerize our application. My requirement is : To assign an ip to a docker container which is accessible from an external application/browser. The container ip should be pingable from a different computer in the same network basically.I don't want to use port forwarding. I want to access a docker container just like we access a VM using an ip address.[ Without the port mapping, -p

Reasons to avoid access modifiers in php [closed]

我怕爱的太早我们不能终老 提交于 2019-11-27 02:34:11
问题 What are valid reasons NOT to use keywords public, private, protected in php? The story: I've started a project with a team that actively uses access modifiers in their code (even "public" explicitly) and wants to convince me to do the same. I always find this kind of stuff totally useless in a dynamic language like php, but I realize that my gut feeling is hardly an argument in a technical discussion. Therefore I'm looking for a solid, clear explanation why access modifiers are useless (or

How to declare Global Variables in Excel VBA to be visible across the Workbook

自作多情 提交于 2019-11-27 02:12:29
问题 I have a question about global scope and have abstracted the problem into a simple example: In an Excel Workbook: In Sheet1 I have two(2) buttons. The first is labeled SetMe and is linked to a subroutine in Sheet1's module : Sheet1 code: Option Explicit Sub setMe() Global1 = "Hello" End Sub The second is labeled ShowMe and is linked to a subroutine in ThisWorkbook's module : ThisWorkbook code: Option Explicit Public Global1 As String Debug.Print("Hello") Sub showMe() Debug.Print (Global1) End

Is it possible to declare a public variable in vba and assign a default value?

≯℡__Kan透↙ 提交于 2019-11-27 02:01:54
问题 I want to do this but it won't compile: Public MyVariable as Integer = 123 What's the best way of achieving this? 回答1: .NET has spoiled us :) Your declaration is not valid for VBA. Only constants can be given a value upon application load. You declare them like so: Public Const APOSTROPHE_KEYCODE = 222 Here's a sample declaration from one of my vba projects: If you're looking for something where you declare a public variable and then want to initialize its value, you need to create a Workbook