Inheritance, abstract and concrete
Given:
*abstract public class Foo {
* protected static int bat;
* public static int bat() {
* return bat;
*public class Bar extends Foo {
* private static int bat = 5;
Assuming that you have complete rewrite power over both classes, is there any way to have a situation where:
* Foo f = new Bar();
* int x = f.bat();
will set x == 5 without putting an identical
* public static int bat() {
* return bat;
in every single class that extends Foo?
It's a complicated situation. I have a large number
of user-defined classes that are all being stored
together. I want to be able to pass them to the same
functions, so I don't have to rewrite the functions a
dozen times with only the variable class changing, so
I defined them all as extensions of one abstract
class, but I also need to be able to tell them apart
when I need to handle them differently. It seemed to
me that the best way to do that was by giving each
different concrete class a distinct id number, that
the handler can use in the rare cases when it's
needed. I thought the id should be declared static
because it belongs to the class, not to individual
instances of the class. But I want to keep it
private, so nobody can mess with it, so I also need a
public function to return it. And since it works
with a static value, it has to be declared as a
static function.This sounds wrong.
If they are user defined classes then it is not possible for you to tell them apart.
Or your terminology means something different.
If you are writing a plug in engine where something is added later, then the engine can no rely on anything specific about the plug ins. If it does, they are not plug ins.
If you need to handle them differently with some common categories of functionality then you should be using interfaces and helper classes.
Pseudo code would be like this...
interface CommonStuff
String getName();
interface Communications
boolean sendInfo();
interface Storage
boolean storeIt();
class PlugInEngine
void process(Object o)
if (o instanceof Communications)
((Communications)o).sendInfo();
if (o instanceof Storage)
((Communications)o).storeIt();
if (o instanceof CommonStuff)
log("Finished name=" + ((CommonStuff)o).getName());
}
Similar Messages
-
Duplicate error for Abstract WSDL and Concrete WSDL
Hi,
I am trying to consume a webservice from ABCS Provider.
Here is what I have done:
1. Loaded target webservice wsdl into MDS by removing it's wsdl:service element.
2. Created a composite with a partnerlink referring to MDS wsdl.
3. Added binding.ws location (with concrete wsdl url) and port.
But when I compile I am getting an error, seems it is conflicting with MDS wsdl and concrete:
Error(73): query "/ns1:createComplaint/arg0/instrumentInstallDate" is invalid, because Global Type declaration/definition of name '{http://tempuri.org/}createComplaintResponse' are duplicated at the following locations:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [line#: 130]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [line#: 120]
There are at least two of them looking different:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [difference starting at line#:132]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [difference starting at line#:122]
Global Type declaration/definition of name '{http://tempuri.org/}createComplaint' are duplicated at the following locations:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [line#: 121]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [line#: 11]
There are at least two of them looking different:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [difference starting at line#:123]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [difference starting at line#:13]
Global Type declaration/definition of name '{http://tempuri.org/}updateComplaint' are duplicated at the following locations:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [line#: 136]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [line#: 134]
There are at least two of them looking different:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [difference starting at line#:138]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [difference starting at line#:136]
Global Type declaration/definition of name '{http://tempuri.org/}updateComplaintResponse' are duplicated at the following locations:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [line#: 145]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [line#: 143]
There are at least two of them looking different:
oramds:/apps/AIAMetaData/AIAComponents/ApplicationObjectLibrary/Agile/V1/wsdls/AgileComplaint_v1.wsdl [difference starting at line#:147]
http://172.25.86.11:8001/holxagileservice/AgileComplaintPort?xsd=1 [difference starting at line#:145]
Thanks
Saisee :
http://blogs.oracle.com/aia/entry/aia_11g_best_practices_for_dec
http://docs.oracle.com/cd/E17904_01/doc.1111/e17364/bestpractices.htm#BABCGHEH
http://eai.ittoolbox.com/groups/technical-functional/tibco-l/abstractconcrete-wsdl-1091495
abstract wsdls can be used on designtime, so in that case the backend service don't have to be online to implement your process.
on runtime the concrete wsdl will be used to lookup for example the actual endpoint (service) and bindings -
Inherited abstract method IGCIControllerDelegate
Hi,
I created only view in NWDS,the implementation it can't recognize the IPrivateview and context values.i deleted and created agine but agine it shows same,and the error is inherited abstract method IGCIControllerDelegate,please give me solution,what is the problem?Hi Sumit,
I closed and agine opened but iam getting the same error.Please tell me . -
The type must implement the inherited abstract method???
import java.awt.*;
import java.awt.event.*;
import java.awt.ActiveEvent;
import java.applet.*;
public class MoveIt extends Applet implements ActionListener
private Image cup;
private Panel keyPad;
public int yaxis = 15;
public int xaxis = 15;
private Button keysArray[];
public void init()
cup = getImage(getDocumentBase(), "cup.gif");
Canvas myCanvas = new Canvas();
setBackground(Color.blue);
setLayout(new BorderLayout());
Button up = new Button("Up");
Button down = new Button("Down");
Button right = new Button("Right");
Button left = new Button("Left");
Button center = new Button("Center");
add(myCanvas, BorderLayout.NORTH);
add(keyPad, BorderLayout.SOUTH);
keyPad.add(up, BorderLayout.NORTH);
up.addActionListener(this);
keyPad.add(down, BorderLayout.SOUTH);
down.addActionListener(this);
keyPad.add(right, BorderLayout.EAST);
right.addActionListener(this);
keyPad.add(left, BorderLayout.WEST);
left.addActionListener(this);
keyPad.add(center, BorderLayout.CENTER);
center.addActionListener(this);
public void paint( Graphics g )
g.drawImage( cup, xaxis, yaxis, this );
public void ActionPerformed(ActionEvent e)
String action = e.getActionCommand();
if(action.equals("Up"))
yaxis = yaxis - 15;
if(action.equals("Down"))
yaxis = yaxis + 15;
if(action.equals("Left"))
xaxis = xaxis - 15;
if(action.equals("Right"))
xaxis = xaxis + 15;
if(action.equals("Center"))
xaxis = 125;
yaxis = 60;
}How come there is an error:
The type MoveIt must implement the inherited abstract method
ActionListener.actionPerformed(ActionEvent)
What the hell does that mean?A class that implements an interface must define the methods of the interface. Your applet (or the one you borrowed) states at the top that it implements the ActionListener interface. If you go to the API, you'll see that this interface declares a method "actionPerformed", and so this class must have a method that matches the one in the interface. I see that your applet will have some Buttons. You'll need an actionPerformed method if you want the buttons to use your class (this) as their action listener.
Edit: I see that you already have an "ActionPerformed" method, but note that case matters, and this is not the same as "actionPerformed". Change one letter and you're on your way.
Edited by: Encephalopathic on Jan 15, 2008 8:44 PM -
Illegal combination of modifiers: abstract and synchronized
Hello all:
I have an error from my java compiler and need some help to know the underlying reason
why this statement is wrong.
the following statement is defined in an abstract class.
public abstract synchronized boolean isLeaf();when I try to compile it, i got the following error.
illegal combination of modifiers: abstract and synchronized
so i know this statement is not valid.
does anyone tell me why?
thank you
-Daneilsynchronization of a method is not inherited. the synchronized keyword, when applied to a method realy is a short-cut to put this about the method body:
//instance method:
synchronized(this)
//static method
synchronized(Blah.class)
}It only applies to the currently declared method. There is no way to require that an implementation of tyour method is synchronized. -
What is difference between abstraction and encapsulation ?
Hi,
I am trying to figure out the difference between abstraction and encapsulation but confused.
Both are used for data hiding then what is the exact difference ?
Thanks.Tushar-Patel wrote:
I am trying to figure out the difference between abstraction and encapsulation but confused.
Both are used for data hiding then what is the exact difference ?This is the picture I have:
When you encapsulate something you get an inside and an outside. The outside is the abstraction. It describes how the encapsulated entity behaves viewed from the outside. This is also called the type. Hidden inside is the implementation. It holds detail information about how the type's behaviour is accomplished.
It's a very simplified picture but I think it's quite accurate and it works for me. -
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; -
Concept of Abstraction and Polymorphism
Hi friends,
I'm just new to Java.I studied a little bit of C, I'm currently studing VB and Java.
There are one or two concepts in Java that are very hard to grasp for me.
The first is abstraction and the second is polymorphism.
Can anybody outline to me in simple words(use simple example if needed)what those 2 concepts are all about?
Thanks a lot
MarcoIn your example, you could make Vehicle an abstract
class. You can't simply have a vehicle, but you can
have a car which IS a vehicle. In your abstract class
Vehicle, you might define an abstract method public
int getSeats() (you want it to be abstract because it
changes from one type of vehicle to the next). So the
class Car extends Vehicle, overrides the method
getSeats() and returns 5. The class Ute extends
Vehicle, overrides the method getSeats() and returns 2
(you might make a SuperCabUte that extends Ute and
returns 5, or whatever).Radish is right,
Think of it as modelling of real life. You would generalise the description of your car as a Vehicle (abstraction, which can be implemented as an interface in Java) where in fact you own a car
Similarly you can have an inteface called RealEstate where in fact you own a TwoStoreyHouse ( a class that implements the RealEstate interface)
the interface can describe the general 'characterstics' of real estate properties ie land size, council rates etc.
HTH...hey.... -
Understanding the combination of inheritance, packages and access modifiers
I am working on a problem to help my practical understanding of accessing inherited members and methods from a different package using both inheritance and instance variable.
Unfortunately, I am totally lost when I tried to set this up and understand what was happening.
Problem:
Create a class named "classA" under package "pack1" with 4 members (int pub_a, int priv_a, int prot_a, int def_a) and methods (pub_func1, priv_func1, prot_func1, def_func1). Mark the members and methods with 4 different access specifiers (public, private, protected, and default)
Create a class named "classB" under package "pack2", ClassB will inherit classA of package pack1. ClassB will have 2 members (int pub_b, int priv_b) and methods (pub_func2, prot_func2) with 2 different access specifiers (public, protected)
Try accessing the members of class classA in package pack1 inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through inheritance.
Create an instance of class classA inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through the instance.
Note: In your solution, comment out the lines that are in-accessible with the actual error message at the top of the comment.
So I produced the following code (I don't think i set this up right):
//filename A.java
package pack1;
public class A {
public int pub_a;
private int priv_a;
protected int prot_a;
int def_a;
public int pub_func1() {return 1;}
private int priv_func1() {return 2;}
protected int prot_func1() {return 3;}
int def_func1() {return 4;}
//filename B.java
package pack2;
import pack1.A;
public class B extends A{
public int pub_b;
private int priv_b;
public int pub_func2() { return 5; }
private int priv_func2() { return 6; }
//directly inherited fields, at least one should be accessible?
pub_a = 1;
priv_a = 1;
prot_a = 1;
def_a = 1;
int i;
// directly inherited methods, at least one should be accessible?
i = pub_func1();
i = priv_func2();
A a = new A();
//not sure what's accessible here, as no error red underlines appear
a.pub_a = 1;
a.priv_a = 1;
a.prot_a = 1;
a.def_a = 1;
}I would be interested to know how one would approach and address this problem.//filename B.java
package pack2;
import pack1.A;
public class B extends A{
public int pub_b;
private int priv_b;
public int pub_func2() { return 5; }
private int priv_func2() { return 6; }
//directly inherited fields, at least one should be accessible?
pub_a = 1;//true
priv_a = 1;// false
prot_a = 1;//true
def_a = 1;//false
int i;
// directly inherited methods, at least one should be accessible?
i = pub_func1();//true
i = priv_func2();//false
A a = new A();
//not sure what's accessible here, as no error red underlines appear
a.pub_a = 1;//true
a.priv_a = 1;//false
a.prot_a = 1//false;
a.def_a = 1;//false
}Edited by: fun_with_me on May 31, 2008 8:30 AM -
Inherited fields and methods shown with the class own fields and methods
In each subclass page, javadoc includes the fields and methods of the superclass as if they were declared in the subclass. However the methods inherited from Object are shown in a separate box.
Is there a way to make javadoc group all inherited fields and mehods in separate boxes, one for each superclass?
I'm using the javadoc tool from J2SE v 1.4.2_07 SDK with NetBeans 4.0 Bundle.
Thanks.Yes, I know it does, but it seems that the superclass
must be declared public.Sort of. Per default javadoc documents public and protected types and members. With this setting, where would you expect the documentation of public members of a package-private super class to be?
If you specify -package or -private as an option for javadoc, package-private and/or private types and members are documented, too, so package-private super classes are documented as usual. -
If java inherites Object , and i inherite another class how possible ?
hey !
if my class B inherits A , and you know that all class inherits a class called Object , then that means B inherts two classes one A (user defined ) and another Object, then is it a violation of rule ? if now how java achieved this feature ? can you justify
for sack of simplicity i wrote following code .
class B extends A
int r;
B(int a)
r=a;
public String toString()
return r +" ";
}Java supports this:
Object
|
A
|
B
|
Cbut not this:
Object
A B
C
Maybe you are looking for
-
IPod not syncing / scrambled by iTunes
For the second time this month, iTunes 10 has decided to freeze/crash while working on my iPod. The first time I was left with an iPod that seemed to still have everything on there, but it was all unaccessible. It claimed there were 0 files on there,
-
Unable to download imac version 7.0 or higher
The hardrive was replaced on my Imac. Was initially unable to log on or do anything. I reinstalled the CD that came with and was then able to reset passwords and get in. I have downloaded available software multiple times and I am still miss many app
-
Transfer media to my lumia 720
Hi. I have been trying to transfer videos and music from my laptop to my Nokia Lumia 720. Some end up playing while most don't, the ones that play end up multiplying themselves. And if I delete the duplicated they don't play. This happens to both mus
-
Deleting Duplicate Rows in a list
Hey folks, I've scowered around a bit for the answer to this and can't for the life of my figure it out. I've got a list of ~2,000-3,000 words in the following format: Fact Fiction Funny Funny Funny Funky etc etc. I am looking to make numbers delete
-
Updation of higher level item text to lower level item text
Hi All, while creating sales order VA01 i need to pass the value of higher level item text to lower level item text for that i read the text of the higher level item text using the fm read_text and pass the text to the lower level items using save_