• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

all abstract methods must implemented by subclass

 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an ABSTRACT Class all abstract methods must implemented by subclass, well may not implemented and INSTEAD, implement overloaded methods of this abstract method?
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you have to implement the abstract method, with the same signature, in a subclass.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to implement all the abstract methods, unless if your sub class is also a abstract class!
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please try it yourself that is a best way to learn.
You will surely get a compiler error if you donot implement the abstract methods unless and untill your subclass is also a abstract class.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this applies and to Stream chain of classes?
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leonidas Savvides wrote:this applies and to Stream chain of classes?

What happen when you try it?
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the BOLD Text of my book, below...

4.4.1 Writers
The Writer class mirrors the java.io.OutputStream class. It's abstract and has two protected constructors. Like OutputStream, the Writer class is never used directly; instead, it is used polymorphically, through one of its subclasses. It has five write() methods as well as a flush( ) and a close( ) method:

protected Writer( )

protected Writer(Object lock)

public abstract void write(char[] text, int offset, int length)

throws IOException

public void write(int c) throws IOException

public void write(char[] text) throws IOException

public void write(String s) throws IOException

public void write(String s, int offset, int length) throws IOException

public abstract void flush( ) throws IOException

public abstract void close( ) throws IOException


The write(char[] text, int offset, int length) method is the base method in terms of which the other four write( ) methods are implemented. A subclass must override at least this method as well as flush( ) and close(), although most override some of the other write( ) methods as well in order to provide more efficient implementations. For example, given a Writer object w, you can write the string "Network" like this:

char[] network = {'N', 'e', 't', 'w', 'o', 'r', 'k'};

w.write(network, 0, network.length);


The same task can be accomplished with these other methods, as well:

w.write(network);

for (int i = 0; i < network.length; i++) w.write(network[i]);

w.write("Network");

w.write("Network", 0, 7);
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leonadis, I expected that you know how to UseCodeTags by now...
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leonidas Savvides wrote:See the BOLD Text of my book, . . .
Which book?
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Network Programming, 3rd Edition OREILLY
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic