Objective-C equivalent of Java "protected" modifier [duplicate] - java

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Protected methods in objective-c
I am a Java developer who is starting to have questions about Objective-C coding syntax.
As of right now, I only see +/- that denotes the Java public/private equivalents.
How would you implement a protected method in Objective-C?

+/- indicates whether a method is a class method or an instance method -- not whether it is public or private.
In short, you can't declare a method as protected in Objective-C. Essentially every method is public, although if you don't declare a method in the header file, it is, in effect, private.

Related

why are access modifies used so much in Java but not in C#? [duplicate]

This question already has answers here:
Access modifier best practice in C# vs Java
(4 answers)
Closed 5 years ago.
Namely, why is the Java main method public but the C# Main method is defaulted to internal? I also find that classes in C# often don't need to denote an access modifier but in Java we slave over ensuring visibility is restricted just to those that need to see the information of these other classes.
In dotnet the Mainmethod doesn't have to be public. It can be private inside a private class and the runtime will still be able to resolve it. You may want to change the modifiers on Main for your own reasons though.
You can find more detailed information here https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/
In general though dotnet developers do (or should) give the same amount of consideration to access modifiers as Java developers.

Access rights and their difference between public and protected members of a Java class? [duplicate]

This question already has answers here:
What is the difference between public, protected, package-private and private in Java?
(30 answers)
Closed 5 years ago.
I know this might be thought of as a duplicate question, but I think my question is a bit different from the previous questions.
The difference between public and protected members is that a public member acts as a protected member on in that it can be accessed from the world but a protected member cannot.
What does the term world mean? Does it mean from outside the class? If so how?
Is it by using the class name? Or they can be accessed by using the variable/method name directly without the current class being a subclass?
Okay, the word "world" means that it can be accessed from anywhere inside the project (no matter if they are in the same package). However the protected members means that they can only be accessed from other classes inside the same package. Sources

What is the Use of "this" keyword in java [duplicate]

This question already has answers here:
What is the meaning of "this" in Java?
(22 answers)
Closed 5 years ago.
I saw multiple use of the keyword this in advanced java programs and in android java files. Can anybody please explain to me the use of this? So I can understand the programming better.
As said by Oracle's Java documentation
:
Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.
I would check out the documentation as the this keyword is used often in programming.

I am very confusion to usage of explicit constructors in java [duplicate]

This question already has answers here:
What is Implicit constructors on Java
(2 answers)
Closed 7 years ago.
In what situation we implement the explicit constructors in java program and when we doesn't need to implement explicit constructors.
This article explains the full story. In short: you need explicit constructors if you want to pass parameters to this constructor. If you do not need this, you can either provide a "parameterless" constructor ( public Foo() {} ), or you do nothing, in which case the system will create an empty one for you in the background.

Why in Java enums are not allowed in method? [duplicate]

This question already has answers here:
Why doesn't Java allow enum to be defined within a method? [duplicate]
(3 answers)
Closed 8 years ago.
Java does not allow enum to be declared in a method that is a basic java syntax.
But
Could any body explain why is that, what could have gone wrong if it would have been allowed by Java, I am sure there must be some cause behind this restriction, any idea?
class Example {
void aMethod() {
//This is not allowed
enum Status {
NEW,
PROCESSING,
COMPLETED;
}
}
}
enum types are typically used to share constant values between classes so declaring them in the scope of a method wouldnt make any sense

Categories

Resources