Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OOP

Posted on 2004-04-23
6
Medium Priority
?
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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 800 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

610 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