OOP

I'd just like to check that my understanding of OOP is correct.

Classes & Interfaces

Interfaces.....
-An interface method must not contain a body.
-When an interface is implemented, all variables are inherited and all methods must be over written
-An interface can be a child (?) of another interface........?

Abstract classes.......
-An abstract class cannot be instantiated
-When extending an abstract class, all abstract methods must be over written
-When extending an abstract class, all methods and variables are inherited

Final classes.... (I'm a bit unsure of this)
-A final class CANNOT be extended
-A final class can be instantiated
-Nothing can be changed in an instance of a final class... (E.g. no get or set methods)


Public classes....
-A public class can be accessed from any class in any package


Methods

Public methods...
-A public method can be accessed from any class in any package ONLY if being accessed via an instance of its class

Private methods...
-Private methods can only be accessed from the class it's contained in.
-If a class containing a private method is extended....the private methods will not be inherited (?)

Static methods....
-A static method can be accessed without creating an instance of its class (e.g. class name is "MyClass" and method name is "myMethod" then it could be accessed like so... MyClass.myMethod();)

Final methods....
I've got no idea about final methods. Can someone please explain how these work?

Protected methods.....
I'm not really sure about these methods... I know it’s got something to do with any sub class of it but an explanation would be great :)


This is just personal homework so hopefully one day I'll become a Certified Java programmer.
I'd prefer an explanation of anything I've got wrong or miss understood however I'm still happy to accept links.
Thanks in advanced.

Cheers

-OBCT
LVL 9
OBCTAsked:
Who is Participating?
 
Tommy BraasConnect With a Mentor Commented:
>> -An interface method must not contain a body.
Cannot would be the right word

>> -When an interface is implemented, all variables are inherited and all methods must be over written
An interface cannot contain variables, only constants and methods. If not all methods from an interface are implemented by an implementing class, then that class must be marked as abstract.

>> -An interface can be a child (?) of another interface........?
An interface can extend multiple other interfaces

>> -An abstract class cannot be instantiated
Correct, not all methods contain method bodies

>> -When extending an abstract class, all abstract methods must be over written
Either that, or the extending class must also be marked as abstract

>> -When extending an abstract class, all methods and variables are inherited
Correct

>> -A final class CANNOT be extended
Correct, this is the reason why you can mark a class as final

>> -A final class can be instantiated
Yes, it would not make sense to be able to mark a class as both final and abstract

>> -Nothing can be changed in an instance of a final class... (E.g. no get or set methods)
Not true. The only thing you can't do with a final class is extend it.

>> -A public class can be accessed from any class in any package
Correct

>> -A public method can be accessed from any class in any package ONLY if being accessed via an instance of its class
Yes and no. A public INSTANCE method requires an instance of the class in order to be accessed. Public static methods  don't require class instances for access

>> -Private methods can only be accessed from the class it's contained in.
Correct

>> -If a class containing a private method is extended....the private methods will not be inherited (?)
They will not be accessible from the sub class, for all practical purposes, they are not inherited

>> -A static method can be accessed without creating an instance of its class (e.g. class name is "MyClass" and method name is "myMethod" then it could be accessed like so... MyClass.myMethod();)
Provided that static method has a suitable access modifier

>> I've got no idea about final methods. Can someone please explain how these work?
Final methods cannot be overridden, they can however be overloaded

>> I'm not really sure about these methods... I know it’s got something to do with any sub class of it but an explanation would be great :)
Protected methods are accessible from sub classes of the defining class, and can be overridden.

I hope that straightened out some of those question marks you had!
0
 
objectsCommented:
lots of good answers/explanations at:
http://www.mindprod.com/jgloss
0
 
d_tanConnect With a Mentor Commented:
Check the sun java pages. . .lots of tutorials there. . .

http://java.sun.com/docs/books/tutorial/java/TOC.html

dtan
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
OBCTAuthor Commented:
Thank you all very much for your help.

orangehead911, your explanation was excelent!!!

d_tan, thanks for the link :)

Cheers

-OBCT
0
 
OBCTAuthor Commented:
Sorry Object's I forgot to give you points.
I'll post a new thread with 50 points for you.
0
 
Tommy BraasCommented:
Thank you! =-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.