Select all of the following statements that are true: A. A d…
Select all of the following statements that are true: A. A default “no-arg” constructor is provided automatically if no constructors are explicitly declared in the class. B. At least one constructor must always be defined explicitly. C. Constructors do not specify a return type. D. Constructors must have the same name as the class. E. Constructors are invoked using the new operator when an object is created.
Read DetailsAssuming that A and B are classes defined in their own .java…
Assuming that A and B are classes defined in their own .java files, what is the output of running A? class A extends B { int x = 1; public static void main(String[] args) { System.out.print(new A().x); System.out.print(new B().x); }}class B { int x = 5;}
Read DetailsWhich of the following statements are true regarding abstrac…
Which of the following statements are true regarding abstract classes? A. If a class contains any abstract methods, the class itself must be marked as abstract. B. An abstract class may contain methods that are not marked as abstract. C. Abstract methods may not contain code within curly braces like regular methods do.
Read DetailsAssume that class A and class B are in their own .java files…
Assume that class A and class B are in their own .java files. What would be printed to the console? class A { public int value = 10; public void print() { System.out.print(this.value + ” “); }}class B extends A { private int data = 20; public void print() { System.out.print(this.data + ” “); } public static void main(String[] args) { A a = new A(); a.print(); B b = new B(); b.print(); A c = new B(); c.print(); }}
Read DetailsWhich of the following statements are correct? A. Classes…
Which of the following statements are correct? A. Classes may extend multiple superclasses listed after the extends keyword in the class definition. B. Classes may implement multiple interfaces listed after the implements keyword in the class definition. C. Interfaces may contain constructors, but if none are specified, a default no-arg constructor is assumed. D. A class that implements an interface must contain all of the methods specified in the interface.
Read Details