9 Topics

Member Avatar for
Member Avatar for asteriskLMNOP

Please bear with me, this is my first post So, I have this superclass called A. And I've 2 subclasses A1 and A2. A has attribute name. A has function toString(). A1 inherits name, and has attribute hair. A1 has a method toString() which goes: string A1::toString(){ string stringA= A::toString(); …

Member Avatar for ravenous
0
1K
Member Avatar for rahul.ch

<? super Animal> means animal or it's superclass only. Then why inside the method it's allowing to add Dog object even though it's a subclass of Animal? This program compiles and runs! import java.util.*; class Cat {} class Animal{Animal() {System.out.println("Animal constructor");}} class Dog extends Animal{Dog() {System.out.println("Dog constructor");}} public class GenericDemo5 …

Member Avatar for rahul.ch
0
334
Member Avatar for rahul.ch

General rules is that: 1) A private method cannot be overridden. 2) Subclass method should be a lower access modifier than a overridden superclass method. But the output of the program is "I am Son". Why? Is it because of the rule 2 the output comes? If that's the case …

Member Avatar for JamesCherrill
0
202
Member Avatar for connect2abhi

Hi Can any one tell me how to call a subclass method from a superclass? For example: I have a class A,B and C. Now B and C extends A. So is there any way that we can call a method of B in A? Thanks Abhishek

Member Avatar for DavidKroukamp
0
12K
Member Avatar for Tupinambiss

I'm getting a mismatch error and I've looked up why it would appear and I'm confused because what I'm doing doesn't match the error cause. Plus I've followed the instructions from a guide that I'm using. The code on irb... >> class Cat >> attr_accessor :name, :age, :gender >> end …

Member Avatar for L7Sqr
0
195
Member Avatar for emcyroyale

Basically this program uses an abstract class which 3 other classes extends to so that in the end an overridden toString() method will print out how many pages must be read for each class. Okay, well this program is for a class, but I am kinda of stuck because my …

Member Avatar for quuba
0
202
Member Avatar for Tsunami49

Hi there. I am currently trying to get my head around using classes across two files. I currently have a super class and a sub class stored in a file and the main function in another. When I try and pass arguments to the class they work fine if the …

Member Avatar for Tsunami49
0
135
Member Avatar for majestic0110

I just wanted to demonstrate a quick point regarding Constructors & inheritance. Look at these two classes and think about what you might expect to see after the main method has run. Notice that ClassB is a subclass (inherits from) of ClassA. So, what do we expect the output to …

Member Avatar for masijade
3
578
Member Avatar for ehsantl

Hello folks I'm trying to do my assignment and I'm really stuck in! I have to classes..Customer and Pensioner (Customer = Super class and Pensioner = Subclass) The Pensioner has a PensionNo extra than Customer class. I have to make a array of Customer class (for 10) and put Customer …

Member Avatar for rbv
3
295

The End.