Question

In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

In Java

  1. Which of the following statements declares Salaried as a subclass of payType?
  1. Public class Salaried implements PayType
  2. Public class Salaried derivedFrom(payType)
  3. Public class PayType derives Salaried
  4. Public class Salaried extends PayType
  1. If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.
  1. False
  2. True
  1. When a subclass overloads a superclass method……….
  1. Only the subclass method may be called with a subclass object
  2. Only the superclass method may be called with a subclass object
  3. Both methods may be called with a subclass object
  4. Neither method may be called with a subclass object
  1. The ……… key word is used to call a superclass constructor explicitly.
  1. this
  2. extends
  3. goto
  4. super
  1. A subclass may call an overridden superclass method by ………
  1. Prefixing its name with the name of the superclass in parentheses
  2. Prefixing its name with the super key word and a dot(.)
  3. Using the extends key word before the method is called
  4. Calling the superclass method first and then calling the subclass method
  1. What type of relationship exists between two objects when one object is a specialized version of another object?
  1. “contains a”
  2. “consists of”
  3. “is a”
  4. “has a”
  1. Every class has a toString method and an equals method inherited from the object class.
  1. False
  2. True
  1. In the following code, what will the call to super do?

public class ClassB extends ClassA

{

public ClassB()

}

Super(40);

System.out.println(“This is the last statement “+ “in the constructor.”);

}

}

  1. It will call the method super and pass the value 40 to it as an argument.
  2. This cannot be determined from the code
  3. It will call the constructor of ClassA tat receives an integer as an argument.
  4. The method super will have to be defined before we can say what will happen.
  1. Replacing inadequate superclass methods with more suitable subclass methods is known as……..
  1. Method upgrading
  2. Tactical inheritance
  3. Method overriding
  4. Method overloading
  1. If ClassC is derived from ClassB which is derived from ClassA, this would be an example of …….
  1. Linear inheritance
  2. A chain of inheritance
  3. Multiple interfaces
  4. Cascading classes
  1. If two methods have the same name but different signatures they are…….
  1. Overridden
  2. Overloaded
  3. Subclass methods
  4. Superclass methods
  1. Because every class directly or indirectly inherits from the Object class. Every class inherits the object class’s members
  1. False
  2. True
  1. If a method in a subclass has the same signature as a method in the superclass, the subclass method……… the superclass method.
  1. Overrides
  2. Overloads
  3. Implements
  4. Inherits
  1. When a subclass extends a superclass, the public members of the superclass become public members of the subclass.
  1. True
  2. False

  1. A(n) ………. Method is a method that appears in a superclass but expects to be overridden in a subclass.
  1. Protected
  2. Abstract
  3. Overloaded
  4. Static
  1. Given the following code:

Line 1    public class ClassA

Line 2     {

Line 3             public ClassA() ()

Line 4             public void method1 (int a) {}

Line 5     }

Line 6     public class ClassB extends ClassA

Line 7     {

Line 8              public ClassB() {}

Line 9              public void method1 () {}

Line 10   }

Line 11   public class ClassC extends ClassB

Line 12   {

Line 13            public ClassC() {}

Line 14            public void method1() {}

Line 15   }

Which method1 will be executed when the following statements are executed?

ClassA item1= new ClassB();

Item.method1();

  1. This is an error and will cause the program to crash
  2. method 1 on Line 9
  3. method1 on Line 14
  4. method1 on Line 4
  1. You can write a super statement that calls a superclass constructor but only in the subclass’s constructor.
  1. True
  2. False
  1. If two methods in the same class have the same name but different signatures, the second overrides the first.
  1. True
  2. False
  1. What will happen if a subclass constructor does not explicitly call a superclass constructor?
  1. Java will automatically call the superclass’s default constructor immediately after the code in the subclass’s constructor executes
  2. Java will automatically call the superclass default constructor just before the code in the subclass constructor executes
  3. It must include the code necessary to initialize the superclass fields
  4. The superclass fields will be set to the default values for their data types
  1. An ArrayList can hold multiple values of several different types of data simultaneously.
  1. True
  2. False
  1. If a[ ] and b[ ] are two integer arrays. The expression a == b compares the array contents.
  1. True
  2. False
  1. The ……. method is used to insert an item into an ArrayList.
  1. Store
  2. putItem
  3. add
  4. insert
  1. Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?
  1. Add
  2. Set
  3. Store
  4. Insert
  1. An ArrayList object automatically expands in size to accommodate the items stored in it.
  1. True
  2. False
  1. Objects in an ArrayList are accessed with subscripts, just like an array.
  1. False
  2. True
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answers:

Which of the following statements declares Salaried as a subclass of payType?
Ans: 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.
Ans False

When a subclass overloads a superclass method
Ans Both methods may be called with a subclass object

The ……… key word is used to call a superclass constructor explicitly.
Ans: Super

A subclass may call an overridden superclass method by
Ans:Prefixing its name with the super key word and a dot(.)

What type of relationship exists between two objects when one object is a specialized version of another object?
Ans: "is a"

Every class has a toString method and an equals method inherited from the Object class.
Ans True


In the following code, what will the call to super do?
public class ClassB extends ClassA

{

public ClassB()

{

Super(40);

System.out.println(“This is the last statement “+ “in the constructor.”);

}

}
Ans: It will call the constructor of ClassA tat receives an integer as an argument.


Replacing inadequate superclass methods with more suitable subclass methods is known as
Ans: Method overriding


If ClassC is derived from ClassB which is derived from ClassA, this would be an example of
Ans: A chain of inheritance

If two methods have the same name but different signatures they are
Overloaded

Because every class directly or indirectly inherits from the Object class. Every class inherits the object class’s members
True

If a method in a subclass has the same signature as a method in the superclass, the subclass method……… the superclass method.
Overrides

When a subclass extends a superclass, the public members of the superclass become public members of the subclass.
True

A(n) ………. Method is a method that appears in a superclass but expects to be overridden in a subclass.
Abstract


Given the following code:
Line 1 public class ClassA
Line 2 {
Line 3 public ClassA() ()
Line 4 public void method1 (int a) {}
Line 5 }
Line 6 public class ClassB extends ClassA
Line 7 {
Line 8 public ClassB() {}
Line 9 public void method1 () {}
Line 10 }
Line 11 public class ClassC extends ClassB
Line 12 {
Line 13 public ClassC() {}
Line 14 public void method1() {}
Line 15 }

Which method1 will be executed when the following statements are executed?
ClassA item1= new ClassB();
Item.method1();

Ans: method 1 on Line 9

You can write a super statement that calls a superclass constructor but only in the subclass’s constructor.
Ans:False

If two methods in the same class have the same name but different signatures, the second overrides the first.
False

What will happen if a subclass constructor does not explicitly call a superclass constructor?
Java will automatically call the superclass’s default constructor immediately after the code in the subclass’s constructor executes


An ArrayList can hold multiple values of several different types of data simultaneously.
True

If a[ ] and b[ ] are two integer arrays. The expression a == b compares the array contents.
False

The ……. method is used to insert an item into an ArrayList.
add

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?
Add

An ArrayList object automatically expands in size to accommodate the items stored in it.
True

Objects in an ArrayList are accessed with subscripts, just like an array.
True


If you have any query regarding the answer please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
In Java Which of the following statements declares Salaried as a subclass of payType? Public class...
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
  • 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.    ...

  • What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that...

    What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...

  • 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...

  • Which one of the following statements is true? If a subclass constructor makes a super) call...

    Which one of the following statements is true? If a subclass constructor makes a super) call with a non-empty list of parameters, then the parameter types must be well defined in the superclass. Abstract classes do not need a constructor since they cannot be instantiated. Each subclass constructor must contain an explicit super() method. For each subclass constructor, there must be a corresponding superclass constructor with the same signature.

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • Java True or false: The code shown on line 9 of the DividendStock class, super(symbol) illustrated...

    Java True or false: The code shown on line 9 of the DividendStock class, super(symbol) illustrated how a subclass can call its parents constructor. call Stock's getProtit method a methods share the same name, call stock's version. Again, you do this using the n have DividendStocks ger of its computation. However, since the two ant to you must explicitly tell the compiler that you w Here is the corrected code, which does compile and elma super keyword. redundancy / returns...

  • please this is Java and i need help Question 5 public class Food { public void...

    please this is Java and i need help Question 5 public class Food { public void Foodmethod_1 (int i) { public void Foodmethod_2 (int i) { } public static void Foodmethod_3(int i) { public class Bankudade extends Food { public static void Foodmethod_1 (int i) { public void Foodmethod_2 (int i) { public void Foodmethod_3 (int i) { > 7 a) Determine which method in the subclass overrides a method in the super class? (6 marks) EV b) Determine which...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • I want to write a superclass with one private attribute and one method in JAVA The super class wi...

    I want to write a superclass with one private attribute and one method in JAVA The super class will later derive into 2 subclasses each with its own private attributes and each with a method that OVERRIDES the superclass method with each subclasses with one method ( that will do something) unique to that subclass. ALL classes must have constructors initializing its attributes and getter/setter methods. Then, in the main method,  keep initializing objects of type superclasses based on user's...

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