Abstract methods probe!!!!!!
HI,
Please help me,
I would like to make changeSize abstract
Problem is subclass Circle AND Triangle
where Circle requiers only one parameter (radius)
and Triangle (two height & width)
abstract public void changeSize(int newSize);
Thanks //jF
I suspect something's severly wrong here ... although
you unify the parameter
passing (using double[]s) if feel (I'm psychic
remember?) that you're still violating
the LSP. IMHO resizing using one parameter versus
resizing using two parameters
are two different things and can't be unified using
polymorphism (the abstract method
in the base class).
Maybe there should be two abstract resize methods
in the base class. All
subclasses are to decide for themselves what to do
given any of the two ...The basic problem is that circles and triangles don't have too much in common to model a good inheritance tree...
Similar Messages
-
Misunderstanding about abstract methods
I think my compiler just taught me something, and after reading the JLS I concluded that I had a misconception about abstract methods. However, if someone could confirm this I would feel more comfortable.
I had defined a class structure like so:public abstract class Grandpa{
public abstract void do();
public abstract class Pa extends Grandpa {
public void do(){
// whatever
public class Child extends Pa {
}I got a compile error indicating that Child must implement do(). I had thought that since there was an implementation provided by Pa that Child didn't need to supply one, but I guess I was wrong. Right? :-)Nested where? Inside Pa? Other? Static?Inside Pa.
It sounds like you're satisfied, but if you want to
continue the discussion, I'll make the standard
request. Come on, you know it, say it with me: Provide
a small, complete, working (in that it doesn't
compile) example that demonstrates this. :-)Yeah, that's exactly what I was working on for the bug report, but I can't get the compile error in my small example. Argh! I'll have to go back some time and build it up to match the other classes until I get the error, because I still get it consistently with the real thing. I have no idea what the key factor is, though - I've tried everything obvious and I don't have time to work through it right now.
No prob. It's a pleasant break from arguing with UJ.
:-)Glad I could offer you a distraction. :-) I'll post here again if I ever figure out what the deal is. -
Is not abstract and does not override abstract method actionPerformed
I dont how to corr. Please help!! and thank you very much!!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class test extends JFrame implements ActionListener, ItemListener
private CenterPanel centerPanel;
private QuestionPanel questionPanel;
private ButtonPanel buttonPanel;
private ResponsePanel responsePanel;
private JButton b1,b2,b3,b4,b5; //Create five references to Jbutton instances
private JTextField t1,t2,t3,t4,t5; //Create five references to JTextField instances
private JLabel label1; //Create one references to JLabel instances
private JRadioButton q1,q2,q3; //Create three references to JRadioButton instances
private ButtonGroup radioGroup; //Create one references to Button Group instances
private int que1[] = new int[5]; //Create int[4] Array
private int que2[] = new int[5];
private int que3[] = new int[5];
private String temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10,
temp11, temp12, temp13, temp14, temp15;
public test (String header)
super(header);
Container container = getContentPane();
label1 = new JLabel ("PLease click on your response to ");
q1 = new JRadioButton("I understand most of the content of this subject",true);
add(q1);
q2 = new JRadioButton("I see the relevance of the subject to my degree",false);
add(q2);
q3 = new JRadioButton("The workload in this subject is appropriate",false);
add(q3);
radioGroup = new ButtonGroup(); //JRadioButton belong to ButtonGroup
radioGroup.add(q1);
radioGroup.add(q2);
radioGroup.add(q3);
JPanel buttonPanel = new JPanel();
JPanel responsePanel = new JPanel();
JPanel questionPanel = new JPanel();
JPanel centerPanel = new JPanel();
b1 = new JButton ("Strongly DISAGREE"); //Instantiate JButton with text
b1.addActionListener (this); //Register JButtons to receive events
b2 = new JButton ("DISAGREE");
b2.addActionListener (this);
b3 = new JButton ("Neither AGREE or DISAGREE");
b3.addActionListener (this);
b4 = new JButton ("AGREE");
b4.addActionListener (this);
b5 = new JButton ("Strongly AGREE");
b5.addActionListener (this);
buttonPanel.setLayout(new GridLayout(5,1));
buttonPanel.add(b1);
buttonPanel.add(b2);
buttonPanel.add(b3);
buttonPanel.add(b4);
buttonPanel.add(b5);
t1 = new JTextField ("0",3); //JTextField contains empty string
t2 = new JTextField ("0",3);
t3 = new JTextField ("0",3);
t4 = new JTextField ("0",3);
t5 = new JTextField ("0",3);
t1.setEditable( false );
t2.setEditable( false );
t3.setEditable( false );
t4.setEditable( false );
t5.setEditable( false );
responsePanel.setLayout(new GridLayout(5,1));
responsePanel.add(t1);
responsePanel.add(t2);
responsePanel.add(t3);
responsePanel.add(t4);
responsePanel.add(t5);
questionPanel.setLayout(new GridLayout(4,1));
questionPanel.add(label1);
questionPanel.add(q1);
questionPanel.add(q2);
questionPanel.add(q3);
centerPanel.add(buttonPanel,BorderLayout.CENTER);
centerPanel.add(responsePanel,BorderLayout.EAST);
container.add(centerPanel,BorderLayout.WEST);
container.add(questionPanel,BorderLayout.NORTH);
q1.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent e )
{ //actionPerformed of all registered listeners
if (e.getSource() == b1) {
que1[0] = Integer.parseInt(t1.getText()) + 1;
String temp1 = String.valueOf(que1[0]);
t1.setText(temp1);
else if (e.getSource() == b2) {
que1[1] = Integer.parseInt(t2.getText()) + 1;
String temp2 = String.valueOf(que1[1]);
t2.setText(temp2);
else if (e.getSource() == b3) {
que1[2] = Integer.parseInt(t3.getText()) + 1;
String temp3 = String.valueOf(que1[2]);
t3.setText(temp3);
else if (e.getSource() == b4) {
que1[3] = Integer.parseInt(t4.getText()) + 1;
String temp4 = String.valueOf(que1[3]);
t4.setText(temp4);
else if (e.getSource() == b5) {
que1[4] = Integer.parseInt(t5.getText()) + 1;
String temp5 = String.valueOf(que1[4]);
t5.setText(temp5);
} //end action performed
q2.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent e )
{ //actionPerformed of all registered listeners
if (e.getSource() == b1) {
que2[0] = Integer.parseInt(t1.getText()) + 1;
String temp6 = String.valueOf(que2[0]);
t1.setText(temp1);
else if (e.getSource() == b2) {
que2[1] = Integer.parseInt(t2.getText()) + 1;
String temp7 = String.valueOf(que2[1]);
t2.setText(temp7);
else if (e.getSource() == b3) {
que2[2] = Integer.parseInt(t3.getText()) + 1;
String temp8 = String.valueOf(que2[2]);
t3.setText(temp8);
else if (e.getSource() == b4) {
que2[3] = Integer.parseInt(t4.getText()) + 1;
String temp9 = String.valueOf(que2[3]);
t4.setText(temp9);
else if (e.getSource() == b5) {
que2[4] = Integer.parseInt(t5.getText()) + 1;
String temp10 = String.valueOf(que2[4]);
t5.setText(temp10);
} //end action performed
q3.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent e )
{ //actionPerformed of all registered listeners
if (e.getSource() == b1) {
que3[0] = Integer.parseInt(t1.getText()) + 1;
String temp11 = String.valueOf(que3[0]);
t1.setText(temp11);
else if (e.getSource() == b2) {
que3[1] = Integer.parseInt(t2.getText()) + 1;
String temp12 = String.valueOf(que3[1]);
t2.setText(temp12);
else if (e.getSource() == b3) {
que3[2] = Integer.parseInt(t3.getText()) + 1;
String temp13 = String.valueOf(que3[2]);
t3.setText(temp13);
else if (e.getSource() == b4) {
que3[3] = Integer.parseInt(t4.getText()) + 1;
String temp14 = String.valueOf(que3[3]);
t4.setText(temp14);
else if (e.getSource() == b5) {
que3[4] = Integer.parseInt(t5.getText()) + 1;
String temp15 = String.valueOf(que3[4]);
t5.setText(temp15);
} //end action performed
}//end constructor test
public void itemStateChanged(ItemEvent item) {
//int state = item.getStateChange();
//if (q1 == item.SELECTED)
public class ButtonPanel extends JPanel
public ButtonPanel()
public class CenterPanel extends JPanel
public CenterPanel()
public class QuestionPanel extends JPanel
public QuestionPanel()
public class ResponsePanel extends JPanel
public ResponsePanel()
public static void main(String [] args)
test surveyFrame = new test("Student Survey") ;
surveyFrame.setSize( 500,300 );
surveyFrame.setVisible(true);
surveyFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}//end main
}//end class testis not abstract and does not override abstract method actionPerformed
Oh, I see that the title of your post is an error message? Ok. Well, the test class is declared as implementing an ActionListener. That means the test class must have an actionPerformed() method. Your test class apparently does not.
It does not appear that the test class needs to implement ActionListener. You are using annonymous classes as listeners. -
Is not abstract and does not override abstract method tablechanged
I will remove all the gui code to make it shorter, but my problem lies with my InteractiveTableModelListener.
public class Meet extends JPanel{
private static void createAndShowGUI() {
JFrame frame = new JFrame("MEET_dataTable");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Meet(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
public class InteractiveTableModelListener implements TableModelListener {
public void TableChanged(TableModelEvent evt) {
if (evt.getType() == TableModelEvent.UPDATE) {
int column = evt.getColumn();
int row = evt.getFirstRow();
dataTable.setColumnSelectionInterval(column + 1, column + 1);
dataTable.setRowSelectionInterval(row, row);
class InteractiveRenderer extends DefaultTableCellRenderer {
protected int interactiveColumn;
public InteractiveRenderer(int interactiveColumn) {
this.interactiveColumn = interactiveColumn;
public Component getTableCellRendererComponent(JTable dataTable,
Object value, boolean isSelected, boolean hasFocus, int row,
int column)
Component c = super.getTableCellRendererComponent(dataTable, value, isSelected, hasFocus, row, column);
if (column == interactiveColumn && hasFocus) {
if ((Meet.this.tableModel.getRowCount() - 1) == row &&
!Meet.this.tableModel.hasEmptyRow())
Meet.this.tableModel.addEmptyRow();
highlightLastRow(row);
return c;
public void highlightLastRow(int row) {
int lastrow = tableModel.getRowCount();
if (row == lastrow - 1) {
dataTable.setRowSelectionInterval(lastrow - 1, lastrow - 1);
else {
dataTable.setRowSelectionInterval(row + 1, row + 1);
dataTable.setColumnSelectionInterval(0, 0);
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}As i say, i have removed all the gui code to make it shorter, but in this code i create the table and add all the model to it. I am being returned with the error
Meet.InteractiveTableModelListener is not abstract and does not override abstract method tableChanged(javax.swing.event.TableModelEvent)in javax.swing.event.TableModelListener
what would be causing this error?
CheersSorry, just figured out my silly error, the method is tableChanged not TableChanged.
cheers
TOPIC CLOSED
Edited by: nick2price on Sep 11, 2008 7:08 AM -
Is not abstract and does not override abstract method ERROR
Hello. I'm new at all this, and am attempting to recreate a sample code out of my book (Teach Yourself XML in 24 Hours), and I keep getting an error. I appriciate any help.
This is the Error that I get:
DocumentPrinter is not abstract and does not override abstract method skippedEntity(java.lang.String) in org.xml.sax.ContentHandler
public class DocumentPrinter implements ContentHandler, ErrorHandler
^This is the sourcecode:
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
public class DocumentPrinter implements ContentHandler, ErrorHandler
// A Constant containing the name of the SAX parser to use.
private static final String PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
public static void main(String[] args)
// Check to see whether the user supplied any command line arguments. If not, print an error and exit.
if (args.length == 0)
System.out.println("No XML document path specified.");
System.exit(1);
// Create a new instance of the DocumentPrinter class.
DocumentPrinter dp = new DocumentPrinter();
try
// Create a new instance of the XML Parser.
XMLReader parser = (XMLReader)Class.forName(PARSER_NAME).newInstance();
// Set the parser's content handler
// parser.setContentHandler(dp);
// Set the parsers error handler
parser.setErrorHandler(dp);
// Parse the file named in the argument
parser.parse(args[0]);
catch (Exception ex)
System.out.println(ex.getMessage());
ex.printStackTrace();
public void characters(char[] ch, int start, int length)
String chars ="";
for (int i = start; i < start + length; i++)
chars = chars + ch;
System.out.println("Recieved characters: " + chars);
public void startDocument()
System.out.println("Start Document.");
public void endDocument()
System.out.println("End of Document.");
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
System.out.println("Start element: " + localName);
for (int i = 0; i < atts.getLength(); i++)
System.out.println(" Attribute: " + atts.getLocalName(i));
System.out.println(" Value: " + atts.getValue(i));
public void endElement(String namespaceURI, String localName, String qName)
System.out.println("End of element: " + localName);
public void startPrefixMapping(String prefix, String uri)
System.out.println("Prefix mapping: " + prefix);
System.out.println("URI: " + uri);
public void endPrefixMapping(String prefix)
System.out.println("End of prefix mapping: " + prefix);
public void ignorableWhitespace(char[] ch, int start, int length)
System.out.println("Recieved whitespace.");
public void processingInstruction(String target, String data)
System.out.println("Recieved processing instruction:");
System.out.println("Target: " + target);
System.out.println("Data: " + data);
public void setDocumentLocation(Locator locator)
// Nada
public void error(SAXParseException exception)
System.out.println("Parsing error on line " + exception.getLineNumber());
public void fatalError(SAXParseException exception)
System.out.println("Fatal parsing error on line " + exception.getLineNumber());
public void warning(SAXParseException exception)
System.out.println("Warning on line " + exception.getLineNumber());Check to make sure that the arguments are consistent with your ContentHandler class. Probably the wrong type.
I think you forgot to include the skippedEntity method, it seems to be missing. Even if an implemented class has a method that you are not using, you still have to include the method in your code even if it doesn't do anything.
Message was edited by:
ChargersTule1 -
...is not abstract and does not override abstract method compare
Why am I getting the above compile error when I am very clearly overriding abstract method compare (ditto abstract method compareTo)? Here is my code -- which was presented 1.5 code and I'm trying to retrofit to 1.4 -- followed by the complete compile time error. Thanks in advance for your help (even though I'm sure this is an easy question for you experts):
import java.util.*;
This program sorts a set of item by comparing
their descriptions.
public class TreeSetTest
public static void main(String[] args)
SortedSet parts = new TreeSet();
parts.add(new Item("Toaster", 1234));
parts.add(new Item("Widget", 4562));
parts.add(new Item("Modem", 9912));
System.out.println(parts);
SortedSet sortByDescription = new TreeSet(new
Comparator()
public int compare(Item a, Item b) // LINE CAUSING THE ERROR
String descrA = a.getDescription();
String descrB = b.getDescription();
return descrA.compareTo(descrB);
sortByDescription.addAll(parts);
System.out.println(sortByDescription);
An item with a description and a part number.
class Item implements Comparable
Constructs an item.
@param aDescription the item's description
@param aPartNumber the item's part number
public Item(String aDescription, int aPartNumber)
description = aDescription;
partNumber = aPartNumber;
Gets the description of this item.
@return the description
public String getDescription()
return description;
public String toString()
return "[descripion=" + description
+ ", partNumber=" + partNumber + "]";
public boolean equals(Object otherObject)
if (this == otherObject) return true;
if (otherObject == null) return false;
if (getClass() != otherObject.getClass()) return false;
Item other = (Item) otherObject;
return description.equals(other.description)
&& partNumber == other.partNumber;
public int hashCode()
return 13 * description.hashCode() + 17 * partNumber;
public int compareTo(Item other) // OTHER LINE CAUSING THE ERROR
return partNumber - other.partNumber;
private String description;
private int partNumber;
}Compiler error:
TreeSetTest.java:25: <anonymous TreeSetTest$1> is not abstract and does not over
ride abstract method compare(java.lang.Object,java.lang.Object) in java.util.Com
parator
public int compare(Item a, Item b)
^
TreeSetTest.java:41: Item is not abstract and does not override abstract method
compareTo(java.lang.Object) in java.lang.Comparable
class Item implements Comparable
^
2 errorsAccording to the book I'm reading, if you merely take
out the generic from the code, it should compile and
run in v1.4 (assuming, of course, that the class
exists in 1.4). I don't know what book you are reading but that's certainly incorrect or incomplete at least. I've manually retrofitted code to 1.4, and you'll be inserting casts as well as replacing type references with Object (or the erased type, to be more precise).
These interfaces do exist in 1.4, and
without the generics.Exactly. Which means compareTo takes an Object, and you should change your overriding method accordingly.
But this raises a new question: how does my 1.4
compiler know anything about generics? It doesn't and it can't. As the compiler is telling you, those interfaces expect Object. Think about it, you want to implement one interface which declares a method argument type of Object, in several classes, each with a different type. Obviously all of those are not valid overrides. -
Product is not abstract and does not override abstract method
Received the following errors.
Product.java:3: Product is not abstract and does not override abstract method ge
tDisplayText() in Displayable
public class Product implements Displayable
^
Product.java:16: getDisplayText() in Product cannot implement getDisplayText() i
n Displayable; attempting to use incompatible return type
found : void
required: java.lang.String
public void getDisplayText()
^
2 errors
Code reads as follows
import java.text.NumberFormat;
public class Product implements Displayable
private String code;
private String description;
private double price;
public Product()
this.code = "";
this.description = "";
this.price = 0;
public void getDisplayText()
String message =
"Code: " + code + "\n" +
"Description: " + description + "\n" +
"Price: " + this.getFormattedPrice() + "\n";
public Product(String code, String description, double price)
this.code = code;
this.description = description;
this.price = price;
public void setCode(String code)
this.code = code;
public String getCode(){
return code;
public void setDescription(String description)
this.description = description;
public String getDescription()
return description;
public void setPrice(double price)
this.price = price;
public double getPrice()
return price;
public String getFormattedPrice()
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(price);
Please help!Received the following errors.
Product.java:3: Product is not abstract and does not
override abstract method ge
tDisplayText() in Displayable
public class Product implements Displayable
^
Product.java:16: getDisplayText() in Product cannot
implement getDisplayText() i
n Displayable; attempting to use incompatible return
type
found : void
required: java.lang.String
public void getDisplayText()
^
2 errors
Code reads as follows
Please use the code tags when posting code. There is a code button right above the text box where you enter your post. Click on it and put the code between the code tags.
These error messages are quite clear in telling what is wrong. You have an Interface called Displayable that specifies a method something like thispublic String getDisplayText() {But in your Product source code, you created thismethodpublic void getDisplayText() {The compiler is complaining because the methods are not the same.
You also need to return a String in the method probalby like thisreturn message; -
Getting error while creating abstract method
hi folks,
i facing issue for ABSTRACT Class.
I am trying to create abstarct method, (refered example from saptechnical site),
I created one attribute i-num, created one method AREA, in implementation area , i made it as Abstract, then i did syntax check, then it is giving below error.
*Class ZTEST_CLASS01_AB,Method AREA
The abstract method "AREA" can only be implemented after its
redefinition (METHODS AREA REDEFINITION).*
i tried all the ways..
created subclass for this, i writted some code in AREA of Sub-class, there it is giving dump, because first one is not activated properly..
could you please somebody help me on this.
SriHello Arshad,
Create a class(ZABSTRACT) and make its type as Abstract( Which means atleast one of its methods is abstract)
We can have abstract classes with all it's methods as non-abstract or concrete. A small example is given below:
CLASS gcl_abstract DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS concrete. "Concrete
ENDCLASS. "gcl_abstract DEFINITION
* CLASS gcl_abstract IMPLEMENTATION
CLASS gcl_abstract IMPLEMENTATION.
METHOD concrete.
WRITE: / `I'm a concrete method`.
ENDMETHOD. "concrete
ENDCLASS. "gcl_abstract IMPLEMENTATION
* CLASS gcl_abstract_sub DEFINITION
CLASS gcl_abstract_sub DEFINITION INHERITING FROM gcl_abstract.
PUBLIC SECTION.
METHODS concrete REDEFINITION.
ENDCLASS. "gcl_abstract_sub DEFINITION
* CLASS gcl_abstract_sub IMPLEMENTATION
CLASS gcl_abstract_sub IMPLEMENTATION.
METHOD concrete.
super->concrete( ).
WRITE: / 'Abstract class might not have abstract methods at all!'.
ENDMETHOD. "concrete
ENDCLASS. "gcl_abstract_sub IMPLEMENTATION
START-OF-SELECTION.
DATA: go_abstract TYPE REF TO gcl_abstract_sub.
CREATE OBJECT go_abstract.
go_abstract->concrete( ).
Although i will agree there is no point in making a class as abstract & having no abstract method
@Sri: Looks like you're trying to implement the abstract method "AREA" in the abstract class hence the error. For abstract method you cannot define their implementation in the corres. abstract class.
BR,
Suhas
Edited by: Suhas Saha on Mar 30, 2011 12:04 PM -
Abstract method called in an abstract class
Hello,
I am writing some code that I'd like to be as generic as possible.
I created an abstract class called Chromozome. This abstract class has a protected abstract method called initialize().
I also created an abstract class called Algorithm which contains a protected ArrayList<Chromozome>.
I would like to create a non abstract method (called initializePopulation()) which would create instances of Chromozome, call their method initialize() and full the ArrayList with them.
In a practical matter, only subclass of Algorithm will be used, using an ArrayList of a subclass of Chromozome implementing their own version of initialize.
I have been thinking of that and concluded it was impossible to do. But I'd like to ask more talented peaple before forgetting it !
Thanks,
VincentOk, let's it is not impossible, juste that I had no idea of how doing it :-)
The difficulty is that Algorithm will never have to deal with Chromozome itself, but always with subclass of Chromozome. This is usually not an issue, but in that case, Algorithm is required to create instances of the desired subclass of Chromozome, but without knowing in advance wich subclass will be used (I hope what I say makes any sense).
Actually I may have found a way in the meantime, but maybe not the best one.
I created in Algorithm an abstract method :
protected abstract Chromozome createChromozome()The method initializePopulation will call createChromozome instead of calling directly the constructor and the initialize() method of Chromozome.
Then subclass of Algorithm will implement the method createChromozome using the desired subclass of Chromozome. -
Hi,
I want to use abstract methods in ABAP. I created an abstract class as base and another 'child' class that extends that class. Now, I want to have different implementations in different child classes. The problem is that the IDE redirects me to the base class when trying to to this. There is no possibility to set the method as abstract.
Do you know if that concept is implemented at all? Maybe I just forgot to configure something?!
What do you propose?
Thank you and best regards,
DanielHi,
If you are creating Local class using SE38, then just by writing "abstact" to the method it behaves like an abstract method.
If you are creating global class SE24, then genrally all interface methods are "abstract" methods so that we can ihberit and can redefine the methods for example: "IF_FLUSH_NOTIFY~BEFORE_FLUSH_NOTIFY" symbol ~ shows that it is an abstract method in the interface before to that.
So, even if it refer to its base class you can just implement them in the child classes by inheriting it.
Hope this helps you if yes try to assign some app. points.
Regards,
Suman -
Can i call non -abstract method in abstract class into a derived class?
Hi all,
Is it possible in java to call a non-abstract method in a abstact class from a class derived from it or this is not possible in java.
The following example will explain this Ques. in detail.
abstract class A
void amethod()
System.out.println(" I am in Base Class");
public class B extends A
void amethod()
System.out.println(" I am in Derived Class");
public static void main (String args[])
// How i code this part to call a method amathod() which will print "I am in Base Class
}Ok, if you want to call a non-static method from a
static method, then you have to provide an object. In
this case it does not matter whether the method is in
an abstract base class or whatever. You simply cannot
(in any object oriented language, including C++ and
JAVA) call a nonstatic method without providing an
object, on which you will call the method.
To my solution with reflection: It also only works,
if you have an object. And: if you use
getDeclaredMethod, then invoke should not call B's
method, but A's. if you would use getMethod, then the
Method object returned would reflect to B's method.
The process of resolving overloaded methods is
performed during the getMethod call, not during the
invoke (at least AFAIK, please tell me, if I'm wrong).You are wrong....
class A {
public void dummy() {
System.out.println("Dymmy in A");
class B extends A {
public void dummy() {
System.out.println("Dymmy in B");
public static void main(String[] args) throws Exception {
A tmp = new B();
Class clazz = A.class;
Method method = clazz.getDeclaredMethod("dummy", null);
method.invoke(tmp, null);
}Prints:
Dymmy in B
/Kaj -
Abstract Method Error and XML Parsing
I am using wl6sp1. I am parsing an XML file from within the
servlet using jaxp1.1 and crimson.
Following is code:
1- SAXParserFactory spf = SAXParserFactory.newInstance();
2- sp = spf.newSAXParser();
3- xr = sp.getXMLReader();
4- xr.setContentHandler(new ParseXML());
5- xr.parse( new InputSource("Example3.xml"));
This program works fine when execute from command line but in servlet on line
3 it says:
"Abstract Method Error"
I have created XML Registry to use Crimson as XML parser rather than default.
I think somehow wl is still using jaxp1.0 which is built in
support in wlsp1.
Whats wrong with the code...or what configuration i am missing???I'm assuming you have already put crimson.jar first in the classpath for the java
command you use to start WebLogic. If so, have you tried putting the servlet in
a .war file with the crimson.jar in its' WEB-INF/lib directory?
Regards,
Mike Wooten
"anyz" <[email protected]> wrote:
>
I am using wl6sp1. I am parsing an XML file from within the
servlet using jaxp1.1 and crimson.
Following is code:
1- SAXParserFactory spf = SAXParserFactory.newInstance();
2- sp = spf.newSAXParser();
3- xr = sp.getXMLReader();
4- xr.setContentHandler(new ParseXML());
5- xr.parse( new InputSource("Example3.xml"));
This program works fine when execute from command line but in servlet
on line
3 it says:
"Abstract Method Error"
I have created XML Registry to use Crimson as XML parser rather than
default.
I think somehow wl is still using jaxp1.0 which is built in
support in wlsp1.
Whats wrong with the code...or what configuration i am missing??? -
How to declare abstract method
given - work worked at first .
fact - then i went to add new entity object names ScottOafE0 . went through all the next sand finished. a package and entity obj already exist. i also tried to put a new package and ScottOafAM in a seperate place. still a no go
when i went to run the form it errors out w/ below msg.
Error(14,8): class xxxoaf.oracle.apps.xxuab.hr.newforms.server.ScottOafEOImpl should be declared abstract; it does not define method setLastUpdateLogin(oracle.jbo.domain.Number) in class oracle.apps.fnd.framework.server.OAEntityImpl
Guess - i tired to put import oracle.apps.fnd.framework.server.OAEntityImpl in the controller file . didnt work
any idea how to define abstract method ?
thanks
scottYou dont need to define your class as abstract, that would not resolve your issue, what is happening is
oracle.apps.fnd.framework.server.OAEntityImpl is a abstract class, and has a method declared as setLastUpdateLogin(oracle.jbo.domain.Number) in class
Now, any class (xxxoaf.oracle.apps.xxuab.hr.newforms.server.ScottOafEOImpl ) extending from this class must either provide a definition to this method (provide the implementation logic), or must itself be declared abstract.
We had a discussion on this issue in the forum , look for the thread.
Thanks
Tapash -
"Abstract" method in a non-abstract class
Hi all.
I have a class "SuperClass" from which other class are extended...
I'd like to "force" some methods (method1(), method2, ...) to be implemented in the inherited classes.
I know I can accomplish this just implementing the superclass method body in order to throw an exception when it's directly called:
void method1(){
throw new UnsupportedOperationException();
}...but I was wondering if there's another (better) way...
It's like I would like to declare some abstract methods in a non-abstract class...
Any ideas?The superclass just models the information held by
the subclasses.
The information is taken from the database, by
accessing the proper table (one for each subclass).??
What do you mean by "models the information"?
You should use inheritance (of implementation) only when the class satisfies the following criteria:
1) "Is a special kind of," not "is a role played by a";
2) Never needs to transmute to be an object in some other class;
3) Extends rather than overrides or nullifies superclass;
4) Does not subclass what is merely a utility class (useful functionality you'd like to reuse); and
5) Within PD: expresses special kinds of roles, transactions, or things.
Why are you trying to force these mystery methodsfrom the superclass?
It's not mandatory for me to do it... I 'd see it
just like a further way to check that the subclasses
implements these methods, as they have to do.That's not a good idea. If the superclass has no relation to the database, it shouldn't contain methods (abstract or otherwise) related to database transactions.
The subclasses are the classes that handle db
transaction.
They are designed as a binding to a db table.And how is the superclass designed to handle db transactions? My guess (based on your description) is that it isn't. That should tell you right away that the subclasses should not extend your superclass. -
Non-abstract methods in a Abstract class
Abstract Class can contain Non-abstract methods.
and Abstract Classes are not instantiable as well
So,
What is the purpose of Non-abstract methods in a Abstract class.
since we can't create objects and use it
so these non-abstract methods are only available to subclasses.
(if the subclass is not marked as abstract)
is that the advantage that has.(availability in subclass)
??For example, the AbstractCollection class (in
java.util) provides an implementation for many of the
methods defined in the Collection interface.
Subclasses only have to implement a few more methods
to fulfill the Collection contract. Subclasses may
also choose to override the AbstractCollection
functionality if - for example - they know how to
provide an optimized implementation based on
characteristics of the actual subclass.Another example is the abstract class MouseAdapter that implements MouseListener, MouseWheelListener, MouseMotionListener, and that you can use instead of these interfaces when you want to react to one or two types of events only.
Quoting the javadocs: "If you implement the MouseListener, MouseMotionListener interface, you have to define all of the methods in it. This abstract class defines null methods for them all, so you can only have to define methods for events you care about."
Maybe you are looking for
-
Can't login with my Apple-ID!
Hello, i've got a problem. By loggin in with my Apple-ID in iTunes it failes and says that i can't connect with iTunes. My internet works and my sis is able to login with here Apple-ID on the same pc... I reinstalled iTunes, but this didn't help. Ple
-
We are using the following sceanrio: R/3 Idoc > IDoc Adapter > XI > JDBC Adapter > SQL databse and reverse. we want to trigger some error messages enroute. But we are not able to finalize the points where we can anticipate for errors, how to catch th
-
Final Cut Pro 6 Crashes at Launch
Hey Everyone, I have been searching around here looking for answers, and havent been able to find one for my problem. I have unistalled compressor and qmaster which had worked for others, but it did not work for me. here is the error report. Could an
-
Tournament Bracket component in flex
I'm trying to write a application for a volleyball tournament i'm going to be having that basically creates a tournament bracket based of a array of teams i have. If somone could just point me in the right direction to start i would appreciate it. T
-
Macbook pro Dust behind LCD- is it a common issue ?
Hello- I am a little bit embarassed. I haver a very nice and perfect MBP 15,4" Glossy- It recently developed a haze gray cloud behind the display- It was an imperfection which developed into a nuissance, since i am a graphics designer and I definite