Solved

OOP

Posted on 2004-04-23
6
445 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
Dev express lookupcombo 3 34
type mismatch (Object[] to double[] 4 33
Need Help! Getting a syntax error and don't understand why 3 31
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

840 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