Solved

OOP

Posted on 2004-04-23
6
433 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
ID: 10904858
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
ID: 10905252
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
ID: 10905896
>> -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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Author Comment

by:OBCT
ID: 10906306
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
ID: 10906309
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
ID: 10906310
Thank you! =-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The viewer will learn how to implement Singleton Design Pattern in Java.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

919 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

14 Experts available now in Live!

Get 1:1 Help Now