In Java
public class ClassB extends ClassA
{
public ClassB()
}
Super(40);
System.out.println(“This is the last statement “+ “in the constructor.”);
}
}
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();
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.
In Java Which of the following statements declares Salaried as a subclass of payType? Public 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 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 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 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. 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 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 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 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 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 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...