|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Homework - Using "super()"
hi, i am new at java and i want to know how can i use super for this 2 constructors
this is the parent class constructor public Room(String building, String roomNumber, int capacity) { Building=building; RoomNumber=roomNumber; Capacity=capacity; } example format for Room " NSB C205 164 " my question is how can i make a sub class so the new sub class format look like this "L|REM|214|25|Chemistry lab" heelp pllzzz |
|
#2
|
||||
|
||||
|
Super class
I don't think this has any thing to do with the constructor in the super class.
Simply invoke super() by passing in all the necessary parameters to it would do. As for changing the format of the display, if there's a method in the class which prints out values in certain format, you simply need to override the method in your subclass. Otherwise, declare a method which prints out the values of all parameters in your desired format.
__________________
When the programming world turns decent, the real world will turn upside down.
|
|
#3
|
|||
|
|||
|
Quote:
alright i got you so for example this how the subclass should look like public subclass extends Room { public subclass(String building, String roomNumber, int capacity) { super (building, roomNumber, capacity); } also about the printing method i got a toString method to print the Room class toString for Room class public String toString() { return(Building+"|"+RoomNumber+"|"+Capacity); }// toString toString for subclass { return ("L"+super.toString()+"fire") } is that right for the toString for the sub class ? |
|
#4
|
|||
|
|||
|
i figured it out ...thanks for your help everything is ok now.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Homework - Using "super()" |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|