access-modifiers

What is the difference between non-static method and static method of an abstract class?

我与影子孤独终老i 提交于 2019-12-01 06:56:42
I know it is not a best practice to use Static method in Abstract class, but what is the difference If I use both Static and non static method in abstract class. I am assuming there is no difference in calling these methods, because we can't create instance for Abstract Class so we can call both Static and Non-static method using class name only. Is there any other difference between them apart from the keyword 'Static'? Ex: Abstract Class: abstract public class AbstractClass { #region Constructor protected AbstractClass(Args args): this(args) { } #endregion #region public static methods

What is the difference between non-static method and static method of an abstract class?

怎甘沉沦 提交于 2019-12-01 05:24:46
问题 I know it is not a best practice to use Static method in Abstract class, but what is the difference If I use both Static and non static method in abstract class. I am assuming there is no difference in calling these methods, because we can't create instance for Abstract Class so we can call both Static and Non-static method using class name only. Is there any other difference between them apart from the keyword 'Static'? Ex: Abstract Class: abstract public class AbstractClass { #region

Why can clone set a private field on another object?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 00:14:49
I'm learning Java, and the book I'm reading has the following example on cloning. In clone() , my first instance is able to set buffer on the new object even though buffer is private . It seems like it should require the field to be protected for this to work. Why is this allowed? Does clone() have special privileges that allows it to access the private fields? public class IntegerStack implements Cloneable { private int[] buffer; private int top; // ... code omitted ... @Override public IntegerStack clone() { try{ IntegerStack nObj = (IntegerStack) super.clone(); nObj.buffer = buffer.clone();

Equivalent of internal in java

痞子三分冷 提交于 2019-11-30 22:45:51
问题 What is equivalent of internal access modifier available in C# for method in Java? (I know default i.e. methods, variables without any scope are having package access but I am looking for keyword equivalent) How can we achieve methods with protected internal scope in Java? 回答1: There's no equivalent of an assembly in Java, so there can't be an equivalent of an access modifier which makes a member available within an assembly. The closest you can get to internal is the default accessibility

Inconsistent accessibility: return type is less accessible than method C#

穿精又带淫゛_ 提交于 2019-11-30 18:18:22
Ok, so this is really wierd. I have a private member, and I want to use it into Form2. I've made a public static method, so that I can get that member into Form2. Here is my code: private static AppController appController; private BreadRepository breadRep; private CakeRepository cakeRep; private SandwichRepository sandwichRep; public Form1() { InitializeComponent(); breadRep = new BreadRepository(); cakeRep = new CakeRepository(); sandwichRep = new SandwichRepository(); appController = new AppController(breadRep , sandwichRep, cakeRep); } public static AppController getController() { return

Why can clone set a private field on another object?

梦想与她 提交于 2019-11-30 18:11:04
问题 I'm learning Java, and the book I'm reading has the following example on cloning. In clone() , my first instance is able to set buffer on the new object even though buffer is private . It seems like it should require the field to be protected for this to work. Why is this allowed? Does clone() have special privileges that allows it to access the private fields? public class IntegerStack implements Cloneable { private int[] buffer; private int top; // ... code omitted ... @Override public

Changes in access of variables for generic classes in Java 7

…衆ロ難τιáo~ 提交于 2019-11-30 11:13:27
Here is a simple example of some code that compiles using Java 6, but does not compile in Java 7. public class Test<T extends Test> { private final int _myVar; public Test(int myVar) { _myVar = myVar; } public int get(TestContainer<T> container){ T t = container.get(); return t._myVar; } private static class TestContainer<T extends Test> { private final T _test; private TestContainer(T test) { _test = test; } public T get(){ return _test; } } } In Java 7, it fails to compile in the get(TestContainer<T> container) method, with the error: error: _myVar has private access in Test I don't

Visual Studio's Access Modifier drop down option is disabled for resource file [closed]

ε祈祈猫儿з 提交于 2019-11-30 11:00:19
Not sure why Access Modifier drop down is disabled for a Resource file. alt text http://img683.imageshack.us/img683/9157/accessmodifier.png Here are file properties: alt text http://img199.imageshack.us/img199/3930/resxprop.png If possible, change your Custom Tool back to the default "ResXFileCodeGenerator". I tried changing a default web app project to use "GlobalResourceProxyGenerator" and it caused the Access Modifier drop down to disable. diepnguyenv Right click on your file resource, choose Properties ( Alt+Enter ) Change Build Action to Embedded Resource Change Custom Tool to

Difference between Private Sub, Function and Class

时光毁灭记忆、已成空白 提交于 2019-11-30 10:58:24
问题 What are the differences between the following: Private Sub Private Function Private Class When should each one be used? 回答1: Private is a modifier than gives the scope of the class, sub, or function. A sub and a function are both subroutines, or sections of code that can be called in the program. The difference between them is that a function has a return value and a sub does not. A class is a group of codes that can include subs, functions, and other stuff. 回答2: Sub is like a function but

MVVM: Should a VM object expose an M object directly, or only through getters delegating to M's getters?

丶灬走出姿态 提交于 2019-11-30 10:27:01
问题 the best way to explain is with example so: this is the model public class Person { public int age; public string name; } this is the view model public class PersonVM { } my question is: should the vm expose the person to the data template or encapsulate the model properties with his own properties? 回答1: The view model should declare its own properties and hide the specifics of the model from the view. This gives you the most flexibility, and helps keep view model-type issues from leaking