• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract and Interface difference

 
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
I kept looking at the Head First Book and wanted to know the difference between an Abstract Class and an Interface.

I asked ChatGPT to tell me the difference.   It explained what each one does and gave sample code.  I have known that part from the book.   I cant see the difference between them except that the interface can implement multiple classes.   I don't know what that would look like.    

The last paragraph from ChatGPT says is pasted here for reference.   I bolded the parts of the text that I need an example for.  I'll look in the book to see where it has two or more classes being implemented at one time.

In summary, abstract classes provide a way to define common behavior and characteristics while allowing for inheritance and code reuse, while interfaces define contracts and allow for multiple inheritance of behavior among unrelated classes. Abstract classes are useful when you have a common base for related classes, whereas interfaces are useful when you want to define a common API for unrelated classes to adhere to.

I'm brain storming here.  
The abstract class contain instance variables and method headers (contracts).  They cannot directly be made into objects.  A second class needs to extend it.  In the extension the methods will override the abstract class

The interface can inherit from multiple classes.  I don't know what that looks like.  It has some rules about constants being static and final. The methods are public.  They don't have instance variables.

They seem so much alike except that the interfaces can inherit from multiple classes.
 
Marshal
Posts: 28258
95
  • Number of slices to send:
    Optional 'thank-you' note:
I always find it's helpful when learning new language features to see a real example of the feature. Seeing a description like you just gave, I don't find that helpful. Do examples not work for you?

Also the fact that a class can implement more than one interface (which isn't what you said) is not a key feature of interfaces and it's not a reason to choose to write an interface rather than an abstract class. People obsess over that because in the old days people grossly overused inheritance instead of composition, which led them to want to inherit more than one superclass.
 
Paul Clapham
Marshal
Posts: 28258
95
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
You read that an interface "defines a contract" but I think that didn't mean anything meaningful to you. Here's an example, then.

If you write a GUI program in Java then you'll be using Swing. You haven't got into that yet, I expect, but since it's a GUI you'll expect it allows you to display buttons which the user can click on, and then the user expects something relevant to happen. This class is called JButton. Don't look it up, it has an eye-watering number of methods and you don't need to know any of that. A JButton can be clicked and then some code will run to do the thing the user wanted done.

Now, they could have designed JButton so you could subclass it and override the (just made up by me) "whenClicked()" method with that code. But that wasn't what they did. They provided an interface named ActionListener. Here's what it looks like:


It's an interface, so we're going to write a class which implements it. Let's call that class Worker. Then there's going to be a contract between Worker and JButton: If the JButton is clicked then it will call Worker's actionPerformed method with a parameter explaining what happened (that's the ActionEvent). And to set up that contract we need to connect a Worker object to the JButton: it has a method named addActionListener(ActionListener) for that. Since Worker implements ActionListener we can say that a Worker IS-A ActionListener, and therefore we can pass a Worker object to the JButton using its addActionListener method.

Here's what that class might look like:

And here's how we might use it:

Now in real life it isn't usually worth creating a whole class for that, so we use anonymous classes or method references, but don't worry about that yet, it's still the same contract being made between two objects using an interface.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Paul,

The interface looks a lot like using an abstract class and then using Extends in the class that uses it.  What is the difference?

I followed the code up to the last line:



I suppose there is a class named clickMe that has an addActionListener method.  new Worker() calls the "class Worker implements ActionListener".   The parameter of  clickMe. addActionListener() is new Worker().   How does new Worker know which method to run (if there was more than one method in the class)?

Thanks,

Kevin

 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Paul,

Oh wait...



clickMe is not a class.   It is a variable of type JButton.

The JButton must have a class named addActionListener.   addActionListener would have a parameter to tell it which class to use.  It would be Worker().

Am I getting closer?

Thanks,

Kevin
 
Saloon Keeper
Posts: 15608
366
  • 2
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:I asked ChatGPT to tell me the difference.


I strongly implore you to stop using ChatGPT as a learning material. It's a useful tool when you already know what you're doing, but when you're still learning you won't be able to tell the sense from the nonsense. ChatGPT suffers from so called "hallucinations", where it will make up a fake answer if it can't arrive at a factually correct one.

In this particular case, the answer was pretty good, but there will be times where it gives out a blatantly false answer, and it will only confuse you more.

I'll look in the book to see where it has two or more classes being implemented at one time.

The interface can inherit from multiple classes.


You keep using the terminology the wrong way around.

Concrete classes aren't "being implemented". They "implement". So you can look for examples of two or more classes "implementing" a common base class.

Similarly, an interface doesn't "inherit from multiple classes". A class can implement/inherit from multiple interfaces.

They seem so much alike except that the interfaces can inherit from multiple classes.


You need to stop looking at the technical differences, and start looking at the conceptual differences.

When you write/use an interface, you're saying: I need something that implements this contract, but I don't really care who implements it, or how they implement it.

When you write an abstract class, the primary purpose is different. You're saying: "I expect two classes to be very similar in implementation, so to make their live easier I will provide a base implementation that they can both inherit.

How does new Worker know which method to run (if there was more than one method in the class)?


It doesn't, and it doesn't have to. It's the code inside of the JButton that decides which method of the Worker to call.

Here is what such code might roughly look like:

As you can see, when an event is fired, the button explicitly calls the actionPerformed() method on every listener that you registered. So even if ActionListener had more than one method, there would be no ambiguity, because the button itself decides which method to call.

Note that the button knows nothing about the Worker class. It only uses the ActionListener contract. By implementing ActionListener, Worker promises to do the things that a button expects from an ActionListener.

The JButton must have a class named addActionListener.


It must have a method named addActionListener(). Again, be careful with your terminology.

addActionListener would have a parameter to tell it which class to use.


It's better to say that it has a parameter that tells it which "implementing instance" to use.

Remember, you're passing it an object reference. The object must be of a type that implements ActionListener. In this particular case, the object is of type Worker, which implements ActionListener.
 
Greenhorn
Posts: 1
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:
The interface looks a lot like using an abstract class and then using Extends in the class that uses it.  What is the difference?


Kevin,

Since you keep asking about the difference between the two I think it would help to understand the historical intent between them and conceptualize them from that perspective instead of getting bogged down in code.

The main idea to focus on is "how much code does each type allow that is concrete/implementation code"?

An abstract class has a ratio of implementation to abstraction that can vary from 100 to 0.

An interface has a ratio of implementation to abstraction that is exactly 0. (More accurately, "was" 0. More on that later).

The Java designers deemed the situation special enough and useful enough for a type definition to have absolutely no concrete implementations but to define method signatures for it to be designated as its own kind of type.

Why? The language does not allow multiple inheritance, but with this layout of available types-of-types, the language can reap the useful benefits of multiple inheritance (only the behavior contract / non-stateful portion) but not suffer the negatives of multiple inheritance.

Why? Because when defining only method signatures (behaviors) you won't end up with a diamond problem and it allows linking worker classes together with a lot of compile-time safety when passing arguments around.

Why still? It'll be hard for you to see the benefits further before diving into generics, complex architectures, and maintainable / extensible frameworks. When you start using libraries that make use of both types it will eventually click with you why would use one rather than the other. At this point you're a chef who only knows how to make a few simple dishes, it'll be difficult to understand why the kitchen has so many pots and pans with little differences.

(Note: the ratio explanation above is not accurate anymore with newer versions of Java allowing default methods in Interfaces, but how the language reached that feature is a different topic)
 
Marshal
Posts: 79393
377
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
Welcome to the Ranch
 
Campbell Ritchie
Marshal
Posts: 79393
377
  • Number of slices to send:
    Optional 'thank-you' note:
JZ: KA is having enough difficulty without coming across new concepts like diamond inheritance.
The simple thing is that an abstract class is one not intended to be instantiated as is. You must create subclasses from it and those subclasses can be declared abstract or can be instantiated.
Example:

You are not allowing Vehicle, Animal, or Fish to be instantiated directly, but you can instantiate Bus, or Lamprey, or six others. An abstract class may contain abstract methods, but doesn't have to contain any. A concrete class isn't allowed any abstract methods.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Stephan,

I keep reading this part:



Stephan,

I made some pictures below so you can know how I am reading the words.  Is it close?

You keep using the terminology the wrong way around.

Concrete classes aren't "being implemented". They "implement". So you can look for examples of two or more classes "implementing" a common base class.



interface A

class B implements A  
Class C implements A  
class  D implements A

Similarly, an interface doesn't "inherit from multiple classes". A class can implement/inherit from multiple interfaces.



interface  E          interface F         interface G  <--first I create the interfaces

Class all_together_now  Implements interface E, interface F, interface G  <--The concrete class
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Stephen,

You need to stop looking at the technical differences, and start looking at the conceptual differences.


When you write/use an interface, you're saying: I need something that implements this contract, but I don't really care who implements it, or how they implement it.



I am a chair.   I exist.  A movie theatre, a restaurant,  a  desk   can utilize me and I don't care what or where I will be used.  

When you write an abstract class, the primary purpose is different. You're saying: "I expect two classes to be very similar in implementation, so to make their live easier I will provide a base implementation that they can both inherit.



I'm a "plant cell"
I can become a root cell  OR a leaf cell OR a flower cell

Question:  Why does "plant cell" have to be marked as abstract?  Can't any class be inherited even without it being abstract?

Thanks,

Kevin
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Paul, J Zal, Campbell,

Please allow me to chat with Stephan for a while in this thread.  I'll go back to reading your posts after.  I'm getting mixed up jumping from one thought to another.

Thanks,

Kevin
 
Marshal
Posts: 4525
572
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:Class all_together_now  Implements interface E, interface F, interface G


To be syntactically correct and following normal naming conventions it would be like this:
 
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:

Similarly, an interface doesn't "inherit from multiple classes". A class can implement/inherit from multiple interfaces.


*** WARNING *** Reading this may add to the confusion.
Although the following is true,  I have NEVER seen this in production code.
An interface MAY inherit (extend) from one or more interfaces.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Stephan.    
I read Campbell's explanation about abstract classes.  It cannot be run like a static class or be instantiated as an object that can be run.  

I now understand how abstract works except for wondering why a non-abstract class couldn't do the same thing.  Couldn't we declare methods that are empty in a non-abstract class,  use inheritance and overwrite the methods in the children?

I am still baffled by interfaces.   I will take a break and read all of this thread again.

Thanks everyone,

Kevin
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Ron,

Your syntax for implements looks like examples I have seen and it was good that you pointed that out.

Thanks,

Kevin
 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:Couldn't we declare methods that are empty in a non-abstract class,  use inheritance and overwrite the methods in the children?


If they return a value they can't be empty. If they aren't abstract then the compiler won't enforce the subclasses to implement them.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
Carey,

I'll skip reading your post since I'm guessing it is an exception case or something special.    

Thanks,

Kevin
 
Campbell Ritchie
Marshal
Posts: 79393
377
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:. . . Campbell's explanation about abstract classes.  It cannot be run like a static class or be instantiated as an object that can be run.

We have never mentioned static classes, but that phrase is confusing and we don't use it.
You can run neither classes nor objects. You can only run methods.

. . . . Couldn't we declare methods that are empty in a non-abstract class,  use inheritance and overwrite the methods in the children? . . .

You can only have empty methods if they have void instead of a return type. I think the answer to your question is, “usually no”.

Thanks everyone,

Kevin

That&apso;s a pleasure
 
Master Rancher
Posts: 4905
74
  • Number of slices to send:
    Optional 'thank-you' note:
Kevin, it's not clear what you mean by an "empty" method.  I think Campbell believes you mean something like this:

However, is it possible you mean something like this?
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Mike,

I was thinking of the top one



Can a class without the word abstract be inherited by the subclass?

Thanks,

Kevin
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Campbell,

I understood abstract when you gave an example
Post Today 11:13:44 AM     Subject: Abstract and Interface difference
JZ: KA is having enough difficulty without coming across new concepts like diamond inheritance.
The simple thing is that an abstract class is one not intended to be instantiated as is. You must create subclasses from it and those subclasses can be declared abstract or can be instantiated.
Example:



Is there a way to show interface and implements in this style?  





 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:
Easiest way is by hand, like you just did.

If you wanted a project to work on you could write a parser that would find all .java files and pull those out of the code. (Easier said than done.)
 
Stephan van Hulst
Saloon Keeper
Posts: 15608
366
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:I am a chair.   I exist.  A movie theatre, a restaurant,  a  desk   can utilize me and I don't care what or where I will be used.


No. It's not the chair that doesn't care how it is used. It's the restaurant, movie theater or desk that doesn't care how the chair ensures that people can sit on it, as long as people can sit on it:

In the example above, the Restaurant doesn't care whether its seating arrangement consists of chairs or stools or maybe even some other kind of seat. It only cares that the seats can accommodate diners. That requirement is expressed by the Seat interface. As you can see, a Seat doesn't have an implementation. It only declares the accomodate() method. That's all that the Restaurant needs. That's what interfaces are for.

It's the same with JButton and ActionListener. The ActionListener interface is there so that JButton can call the actionPerformed() method. JButton doesn't know about Worker. How would JButton call the actionPerformed() method if there wasn't an ActionListener interface?

I'm a "plant cell"
I can become a root cell  OR a leaf cell OR a flower cell

Question:  Why does "plant cell" have to be marked as abstract?  Can't any class be inherited even without it being abstract?

I now understand how abstract works except for wondering why a non-abstract class couldn't do the same thing.


Presumably, PlantCell contains some method that it can't implement, because the implementation depends on the specific type of plant cell. If it can't implement a method, then it must be abstract.

Couldn't we declare methods that are empty in a non-abstract class,  use inheritance and overwrite the methods in the children?


Sure, but why would you do that? That way, you'd just run the risk that people forget to override the method.

If the method is abstract, then there is no risk of people forgetting to implement it. You MUST implement it, otherwise the application won't compile.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
I watched this video on YouTube about interfaces.  I understand it but want to make sure it is correct.    If anyone has interest could you tell me if it is accurate?

https://www.youtube.com/watch?v=GhslBwrRsnw



Everything before the Restaurant class made sense.   I have very little idea after that.  
 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote://Are the above lines instance variables?


Well, they're not "static"....
 
Rancher
Posts: 285
14
  • Number of slices to send:
    Optional 'thank-you' note:
I think the easiest way to understand this is by saying a Class is basically a custom data type. Like you have generic types int, double, string, and so forth, but Class lets you create your custom type to represent an "object" like a car.  A specific type of car, like a ford mustang, could be derived from a generic class Car. An interface could be provided that guarantees the features in that vehicle. The interface could also be given to a motorcycle which isn't even a type of Car! The interface isn't a data type, it is not a car or motorcycle, it's more like a description of what features the object needs. A reason to use interface is for example, prevent you from building a car which doesn't have any brakes. The interface should guarantee that all the basic features needed by a vehicle are there. There would be a method signature there saying "brakes" and the interface would force you to implement that method in your class, you'd have to write that method from scratch if it didn't exist somewhere already, and you can't compile the program until you implement every single method specified by the interface.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
I watched a few YouTube videos regarding abstract classes and interfaces.   This is a high level of what I understand:

abstract classes
You cannot instantiate them.   myObj = new someAbstractclass;  wont compile.
Abstract classes can have some or all of the methods be Abstract.
Another class extends the abstract class.  The  methods that have code between the squiggle brackets are inherited and can be used as is or they can be overwritten.
The abstract methods have to be overwritten and given a body with code between its squiggle brackets.

interface
These can not be instantiated either.
None of the methods can have a body.
one or more interfaces can be implemented in a different class
Each method has to be overwritten or the compiler will complain.
Interfaces are a contract.  The classes that uses them must give a body to each of the methods.

This is how much I understand and I hope I have this part accurate or very close.

Then there is a big jump for me when it gets to other details that all of you and the book are explaining.  

Ill read the sorting chapter again and also this thread to see what else I can understand.

AFter that I'll write some code and explore.

There are about 20 questions in the sort chapter in the book.  They don't make any sense to me now.  I'll try them on my own and then start a new thread just for the questions.

Thanks all of you continuing to have patience with me.  Once I understand all of this I'd like to make a YouTube video from an amateur's point of view. I have been in situations where others hit a "wall" and go another direction or give up.  I like to keep working at it.  

I have been reading all of the posts.  Sometimes they don't make sense until I understand what something means.  For example signature and contract were strange until I caught on.  

Thanks to all of you not abandoning me.  

Kevin


 
Campbell Ritchie
Marshal
Posts: 79393
377
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:I watched a few YouTube videos . . .

Beware. I have seen vey few YouTube videos that even approach being any good. Most aren't actually wrong, but some are. Most are incomplete and assume their viewers know much more than they actually do.
 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:abstract classes
You cannot instantiate them.   myObj = new someAbstractclass;  wont compile.
Abstract classes can have some or all of the methods be Abstract.
Another class extends the abstract class.  The  methods that have code between the squiggle brackets are inherited and can be used as is or they can be overwritten.
The abstract methods have to be overwritten and given a body with code between its squiggle brackets.

interface
These can not be instantiated either.
None of the methods can have a body.
one or more interfaces can be implemented in a different class
Each method has to be overwritten or the compiler will complain.
Interfaces are a contract.  The classes that uses them must give a body to each of the methods.


Seems like you have the concepts now but I'm disturbed by your imprecise use of terms.

Java has nothing called "overwritten", it has "overridden" and "overloaded".
"{}" are  called "braces", not "curly braces" or "squiggle brackets".
"[]" are called "brackets", not "square brackets".
Writing a method without a body is a "declaration", or to "declare" a method.
Writing a method with a body is a "definition", or to "define" a method.

It's good to see you making progress.
 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:

Campbell wrote:Beware. I have seen vey few YouTube videos that even approach being any good. Most aren't actually wrong, but some are. Most are incomplete and assume their viewers know much more than they actually do.



The two YouTube videos on interfaces were close in information.  

When watching YouTube videos I'm often concerned that the person making them is mostly wrong.    The videos had less details but nothing went against what all of you on Code Ranch were writing to me.

Here is my first instructional video that I created six months ago.  It's for installing a new back up camera in my car.  I tell the audience that I was learning as I went along.  I was surprised to get thousands of views.

https://www.youtube.com/watch?v=h4JdOlUsKaU&t=110s

Thanks,

Kevin


 
kevin Abel
Ranch Foreman
Posts: 906
8
  • Number of slices to send:
    Optional 'thank-you' note:
Carey,

My usage of terms was way off.    Thanks for correcting the words.

Kevin
 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:Is there a way to show interface and implements in this style?


Here's a scanner that will extract those from all .java files in a given directory tree.

EDIT:
I've made some improvements to this so it will find things like
Not wanting to hijack this thread I'm not going to post it. If you are interested let me know and I'll start a new thread.
 
Paul Clapham
Marshal
Posts: 28258
95
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:abstract classes
You cannot instantiate them.   myObj = new someAbstractclass;  wont compile.
Abstract classes can have some or all of the methods be Abstract.
Another class extends the abstract class.  The  methods that have code between the squiggle brackets are inherited and can be used as is or they can be overwritten.
The abstract methods have to be overwritten and given a body with code between its squiggle brackets.

interface
These can not be instantiated either.
None of the methods can have a body.
one or more interfaces can be implemented in a different class
Each method has to be overwritten or the compiler will complain.
Interfaces are a contract.  The classes that uses them must give a body to each of the methods.



Unfortunately all of this just tells you how to use them. It's sort of like reading how to use and maintain a lawnmower, when you just immigrated from Somalia and have no idea why you would want to use one.
 
Campbell Ritchie
Marshal
Posts: 79393
377
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:. . . Can a class without the word abstract be inherited by the subclass?

Thanks,

Kevin

That question shows you are confused about nomenclature. You cannot inherit a class, but only its members. Non‑private mmbers of a class are implicitly inherited by its subclasses. You can subclass a class if it isn't labelled final and has an accessible constructor. Private constructors are not accessible to other code. Constructors don't count as members and aren't inherited by sybtypes.

Is there a way to show interface and implements in this style?  

This is a simplified version of this and this.
 
S Fox
Rancher
Posts: 285
14
  • Number of slices to send:
    Optional 'thank-you' note:
i think it's a good time for you to try making a GUI app with java swing and see what you can learn from that. extend the jframe class, use implements ActionListener for buttons, lots of real world use for the concepts.

also since you are learning about subclasses you need to learn about super keyword too. java compiler automatically adds it so you may never have needed to use it before.
eventually you run into a situation where you do need to use it yourself.


Note: If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.

If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, you might think that there will be a whole chain of constructors called, all the way back to the constructor of Object. In fact, this is the case. It is called constructor chaining, and you need to be aware of it when there is a long line of class descent.


Java Superclass

 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:

S Fox wrote:i think it's a good time for you to try making a GUI app with java swing and see what you can learn from that.


While I agree with you that Swing stretches ones' understanding regarding interfaces and abstract classes, I think it is too complex a subject for an early beginner to start  with.
 
Carey Brown
Saloon Keeper
Posts: 10779
86
  • Number of slices to send:
    Optional 'thank-you' note:

Carey Brown wrote:Here's a scanner that will extract those from all .java files in a given directory tree.


I've made some improvements to this so it will find things like
Not wanting to hijack this thread I'm not going to post it. If you are interested let me know and I'll start a new thread.
 
Campbell Ritchie
Marshal
Posts: 79393
377
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:. . . Can a class without the word abstract be inherited by the subclass?

Thanks,

Kevin

That question shows you are confused about nomenclature. You cannot inherit a class, but only its members. Non‑private mmbers of a class are implicitly inherited by its subclasses. You can subclass a class if it isn't labelled final and has an accessible constructor. Private constructors are not accessible to other code. Constructors don't count as members and aren't inherited by sybtypes.

Is there a way to show interface and implements in this style?  

This is a simplified version of this and this.
 
S Fox
Rancher
Posts: 285
14
  • Number of slices to send:
    Optional 'thank-you' note:
There are also nested classes:
"A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private."
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |