473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

calling method from extended Classes

I am basically using Java Constructor chaining, to try and add vehicles to my TrafficQueue. If I run the below code:



The part of code I am struggling to get working is
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     public void add(RoadVehicle vehicle) {
  4.         if (isFull()) {
  5.             System.out.println("Queue is full! We cannot add any more vehicles to the Queue!");
  6.             System.exit(1);
  7.         } else {
  8.  
  9.  
  10.             if (vehicle instanceof EmergencyVehicle && vehicle.isEmergency())  {
  11.  
  12.                 addToFront(vehicle);
  13.             } else {
  14.                 addToBack(vehicle);
  15.             }
  16.  
  17.         }
  18.     }
  19.  
It wont allow me to run the method isEmergency() on vehicle.


FireEngine class:
Expand|Select|Wrap|Line Numbers
  1. public abstract class  EmergencyVehicle extends RoadVehicle {
  2.  
  3.  
  4.     public boolean codeBlue = true;
  5.  
  6.  
  7.  
  8.     public EmergencyVehicle(String colour){
  9.         super(colour);
  10.     }
  11.  
  12.  
  13.  
  14.  
  15.  
  16.     public boolean isEmergency() {
  17.         return codeBlue;
  18.     }
  19.  
  20.     public void setEmergency(boolean newEmergency) {
  21.         codeBlue = newEmergency;
  22.     }
  23.  
  24. }
  25.  
and EmergencyVehicle class:

Expand|Select|Wrap|Line Numbers
  1. public class FireEngine extends EmergencyVehicle {
  2.  
  3.  
  4.     public FireEngine(String colour) {
  5.         super (colour);
  6.  
  7.     }
  8.     public FireEngine() {
  9.         this("red");
  10.  
  11.     }
  12.  
  13.  
  14.     public String toString () {
  15.         if ("red".equals(colour)) {
  16.  
  17.             return "Fire Engine : CODEBLUE";
  18.  
  19.  
  20.        }   else
  21.             return colour + " FireEngine.";
  22.     }
  23. }
  24.  
So, using extends, I am trying to add the vehicle to the front of the queue, if it isEmergency returns true.

The error I get is:
error, cannot find symbol.

I don't need the exact solution, but I think it should work as I have got the extends in each class. Can anyone point out where it goes wrong? I realise that the code needs neatening up slighty!

When adding a vehicle to the queue, I use

Expand|Select|Wrap|Line Numbers
  1. FireEngine car1 = new FireEngine("red");
  2.  
Nov 29 '16 #1
0 1163

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gilles A. | last post by:
Hi all, Does anyone know how to get the class.method name of the calling method? Example public class A { public void m() { new B().method();
2
by: juchytil | last post by:
Here is a method that calls a static GetInfo() method on the MyObject class. public void MethodName(string param1, int param2) { MyObject.GetInfo(); } Is there any way for the GetInfo()...
8
by: Rakehs | last post by:
Hi, I have a method Show() which is invoked by several methods at different intervals. I want to identify the calling method within Show() whenever it is invoked. How do i do this? Thanks in...
1
by: Jake Barnes | last post by:
I can not figure out the meaning of this error: Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: http://www.bluecasts.com/pdsIncludes/pdsAjax.js ::...
0
by: Jeremy Cowles | last post by:
Hi all, I have recently come up with a way to get the calling method of the current method, and I just want to know if this is a sound way to go about it: Sub CallingMethod() Call...
3
by: Matt F. | last post by:
I have an abstract class that about a dozen sub-classes inherit from. I want to enforce that each sub-class shadows an event in the abstract class, but can't quite figure out how to do this. ...
1
by: candexis | last post by:
So I am working with classes and I have the following Method, which rotate a variable: unsigned __int64 Subkeys::RotaionalLeftShift() { unsigned __int64 top_bits = 0; top_bits = K >>...
3
by: Rupe | last post by:
I wish to add an event to an element, but I wish to add arguments to the calling method, eg like so: element.attachEvent('onclick',startDragDrop('arg1',arg2')) I understand this is not...
4
by: gizz | last post by:
Hi, I'd like to get the name of the calling method. I can't find the solution. For example : function MyFct() { return TheOtherFct() ; }
4
guillermobytes
by: guillermobytes | last post by:
Hello, I was wondering the cost of creating an instance of an extended class. By that I mean, if I have classes: - A - A1 and A2, where: A1 and A2 extend class A. what do instances A1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.