Question

Assume Superis the name of a superclass and Subis the name of a subclass. If we...

Assume Superis the name of a superclass and Subis the name of a subclass. If we have:

Super s = new Sub();

we can only invoke the methods defined in Super class, and we cannot access the methods added by the Sub class. Is this statement true or false?

A. true

B. false

I appreciate if you put some descritions

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

This statement is FALSE. To prove it, I am giving you the below code and the screenshot, so that it is clear to you.

Super.java

public class Super {

    public void method1(){ // method has just a simple print statement

        System.out.println("method1() from base");

    }

}

SubClass.java

public class SubClass extends Super {

    public void method1(){ // this method is also declared in Super class

        System.out.println("method1() from derived");

    }

}

TestDerived.java

public class TestDerived {
    public static void main(String [] args){

        Super s = new SubClass();
        s.method1(); // method of SubClass gets called

    }
}

Good Luck!!! Thank you

Add a comment
Know the answer?
Add Answer to:
Assume Superis the name of a superclass and Subis the name of a subclass. If we...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • ATM Revisited In Java, design a subclass of the Account class called GoldAccount. It is still...

    ATM Revisited In Java, design a subclass of the Account class called GoldAccount. It is still an Account class, however it has an additional field and some additional functionality. But it will still retain all the behavior of the Account class. Write a class called GoldAccount. This class will have an additional private field called bonusPoints. This field will require no get or set methods. But it will need to be initialized to 100 in the constructor. Thereafter, after a...

  • QUESTION 31 The tkinter command _____ kicks off the GUI event loop. goloop() doloop() mainloop() loopDloop()...

    QUESTION 31 The tkinter command _____ kicks off the GUI event loop. goloop() doloop() mainloop() loopDloop() 2.5 points    QUESTION 32 Which of the following statements about superclasses and subclasses is true? A subclass is not connected to a super class in any way A superclass inherits from a subclass. A superclass extends a subclass. A subclass extends a superclass. 2.5 points    QUESTION 33 Pickled objects can be loaded into a program from a file using the function ____....

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • (1)     ____ is the principle that allows you to apply your knowledge of a general category...

    (1)     ____ is the principle that allows you to apply your knowledge of a general category to more specific objects.           a.       Inheritance              c.       Encapsulation           b.       Polymorphism                    d.       Override (2)     When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically.           a.       fonts                      c.       class names           b.       methods                  d.       arrays (3)     By convention, a class diagram contains the ____ following each attribute or...

  • Now design a class named PassengerJet in the file named PassengerJet.java as a subclass of Jet...

    Now design a class named PassengerJet in the file named PassengerJet.java as a subclass of Jet implemented in Problem 2 above. This class should include the following attributes (fields): l numPassengers that represents the number of passengers the jet can carry. l numEngines: The number of engines the Jet has l hasAutopilot: The aircraft has full autopilot capabilities. Additionally, write the following methods: l isHardToFly: This returns a Boolean. The jet is hard to fly if there is no autopilot....

  • 1.     When a sub class object is created, when is the call to the super class...

    1.     When a sub class object is created, when is the call to the super class constructor made? How does a programmer call the super class constructor from the sub class? What do all classes indirectly extend? What methods does every class inherit from the Object class? 2.     When writing methods in a sub class, how can those methods call the methods from the parent class? 3.     Which class is more specific, a super class or a sub class? 4.    ...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • 44 A method signature defines which of the following? (choose all that apply) return type name...

    44 A method signature defines which of the following? (choose all that apply) return type name call parameters body 45 An abstract class can be implemented using the implements keyword. True False 46 An abstract class can be extended using the extends keyword. True False 47 Abstract classes are represented in UML by: italics underline plus/minus bold 48 An abstract class is a superclass for a subclass. True False 49 These symbols are used to denote an interface in a...

  • In the first exercise, you will override the add method in a subclass in order to...

    In the first exercise, you will override the add method in a subclass in order to improve its performance. In the second exercise, you will implement an Iterator for your new linked list class. Exercise 1 The add method of the linked list class discussed during lecture performs in O(N) time. What can be done to improve its performance to O(1)? What are the boundary cases? Define a new class that inherits from the CS20bLinkedList class introduced during the lecture....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT