Solved

OOP

Posted on 2004-04-23
6
428 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:OBCT
6 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
lots of good answers/explanations at:
http://www.mindprod.com/jgloss
0
 
LVL 2

Assisted Solution

by:d_tan
d_tan earned 50 total points
Comment Utility
Check the sun java pages. . .lots of tutorials there. . .

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

dtan
0
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 200 total points
Comment Utility
>> -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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 9

Author Comment

by:OBCT
Comment Utility
Thank you all very much for your help.

orangehead911, your explanation was excelent!!!

d_tan, thanks for the link :)

Cheers

-OBCT
0
 
LVL 9

Author Comment

by:OBCT
Comment Utility
Sorry Object's I forgot to give you points.
I'll post a new thread with 50 points for you.
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
Thank you! =-)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json format text only 4 64
word0 challenge 3 55
Find and Replace Stream with 0s 8 42
When i run adoquery my application freezes 26 89
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video teaches viewers about errors in exception handling.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now