JAVA Question 1 Which of the following statements best describes inheritance in
ID: 3717323 • Letter: J
Question
JAVA
Question 1
Which of the following statements best describes inheritance in Java?
Question 2
Which of the following statements best describes the throws statement in Java?
Question 3
This occurs when a local variable hides an instance field from being used.
Question 4
Which of the following is NOT TRUE about run-time exceptions?
Question 5
What Java keyword is used when defining a class that inherits from another class?
Question 6
What Java keyword is used to refer to an element (field, method, constructor, …) in the direct parent of a class?
Question 7
Which of the following statements describe method overriding?
Question 8
Which of the following statements describe method overloading?
Question 9
What is the main difference between an abstract class and a normal class?
Question 10
What is the main difference between a final class and a normal class?
Question 11
TRUE or FALSE: all classes inherit from the Object class in Java.
Question 12
TRUE or FALSE: the Try-Catch structure is used in error handling and recovering from problems that could crash a program.
Question 13
TRUE or FALSE: you must always override inherited methods.
Question 14
Which statement best describes the difference between a superclass and a subclass?
Question 15
Use the following code to answer the question:
public class Book {
private String title;
private String author;
public Book(String title, String author) {
title = title;
author = author;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return title;
}
}
What is the problem with the above code?
Question 16
Use the following code to answer the question:
public class Book {
private String title;
private String author;
public Book(String title, String author) {
title = title;
author = author;
}
public getTitle() {
return title;
}
public getAuthor() {
return title;
}
}
TRUE or FALSE: the above code will cause a compiler error.
Question 17
Use the following code to answer the question:
public class Book {
private String title;
private String author;
public Book(String title, String author) {
title = title;
author = author;
}
public getTitle() {
return title;
}
public getAuthor() {
return title;
}
}
What can be done to fix the problem?
Question 18
Use the following code to answer the question:
try {
Scanner inputStream = new Scanner(new FileReader(''MyFile.txt"));
String line = inputStream.nextLine();
System.out.println(line);
message = "RCGC CSC 210";
}
catch (Exception ex) {
message = "Problem";
}
What string is reference by the variable message when no problems occur in the try block?
Question 19
Use the following code to answer the question:
try {
Scanner inputStream = new Scanner(new FileReader(''MyFile.txt"));
String line = inputStream.nextLine();
System.out.println(line);
message = "RCGC CSC 210";
}
catch (Exception ex) {
message = "Problem";
}
What string is reference by the variable message when a problem does occur in the try block?
Question 20
Use the following code to answer the question:
int result = 0;
try {
Scanner inputStream = new Scanner(new FileReader(''MyFile.txt"));
String line = inputStream.nextLine();
System.out.println(line);
message = "RCGC";
result = -1;
}
catch (Exception ex) {
message = "Problem";
}
finally {
message = "CSC 210"
}
What are the values of the variables message [message] and result [result] when there is a problem opening the file inside the try block?
Question 21
Use the following code to answer the question:
int result = 0;
try {
Scanner inputStream = new Scanner(new FileReader(''MyFile.txt"));
String line = inputStream.nextLine();
System.out.println(line);
message = "RCGC";
result = -1;
}
catch (Exception ex) {
message = "Problem";
}
finally {
message = "CSC 210"
}
What are the values of the variables message [message] and result [result] when no problems occur in the try block?
Question 22
Use the following code to answer the question:
public class ClassA {
public String fieldX;
public String fieldY;
private int fieldZ;
public ClassA() {
System.out.println("Class A");
}
private void method1() {
...
}
public int method2() {
...
}
}
public class ClassB extends ClassA {
private String fieldA;
private String fieldB;
public ClassB() {
System.out.println("Class B");
}
public void method3() {
...
}
}
ClassA objA = new ClassA();
ClassB objB = new ClassB();
Which class is the superclass [superclass]? Which class is the subclass [subclass]?
Question 23
Use the following code to answer the question:
public class ClassA {
public String fieldX;
public String fieldY;
private int fieldZ;
public ClassA() {
System.out.println("Class A");
}
private void method1() {
...
}
public int method2() {
...
}
}
public class ClassB extends ClassA {
private String fieldA;
private String fieldB;
public ClassB() {
System.out.println("Class B");
}
public void method3() {
...
}
}
ClassA objA = new ClassA();
ClassB objB = new ClassB();
What class members of ClassB does objA inherit?
(Select all the items that would be directly accessed from the objA variable)
Question 24
Use the following code to answer the question:
public class ClassA {
public String fieldX;
public String fieldY;
private int fieldZ;
public ClassA() {
System.out.println("Class A");
}
private void method1() {
...
}
public int method2() {
...
}
}
public class ClassB extends ClassA {
private String fieldA;
private String fieldB;
public ClassB() {
System.out.println("Class B");
}
public void method3() {
...
}
}
ClassA objA = new ClassA();
ClassB objB = new ClassB();
What class members of ClassA does objB inherit?
(Select all the items that would be directly accessed from the objB variable)
Question 25
Use the following code to answer the question:
public class ClassA {
public String fieldX;
public String fieldY;
private int fieldZ;
public ClassA() {
System.out.println("Class A");
}
private void method1() {
...
}
public int method2() {
...
}
}
public class ClassB extends ClassA {
private String fieldA;
private String fieldB;
public ClassB() {
System.out.println("Class B");
}
public void method3() {
...
}
}
ClassA objA = new ClassA();
ClassB objB = new ClassB();
What displays on the screen when the following constructor is called?
ClassA objA = new ClassA();
Question 26
Use the following code to answer the question:
public class ClassA {
public String fieldX;
public String fieldY;
private int fieldZ;
public ClassA() {
System.out.println("Class A");
}
private void method1() {
...
}
public int method2() {
...
}
}
public class ClassB extends ClassA {
private String fieldA;
private String fieldB;
public ClassB() {
System.out.println("Class B");
}
public void method3() {
...
}
}
ClassA objA = new ClassA();
ClassB objB = new ClassB();
What displays on the screen when the following constructor is called?
ClassB objB = new ClassB();
Question 27
Use the following code to answer the question:
public class ClassA {
...
}
public class ClassB extends ClassA {
...
}
TRUE or FALSE: the following statement is legal and will not cause a compiler error?
ClassA objC = new ClassB();
Question 28
Use the following code to answer the question:
public class ClassA {
...
}
public class ClassB extends ClassA {
...
}
TRUE or FALSE: the following statement is legal and will not cause a compiler error.
ClassB objD = new ClassA();
Question 29
Question 30
Question 31
Question 32
Use the following code to answer the question:
ArrayList products = new ArrayList ();
products.add(new Book());
products.add(new Movie());
products.add(new Product());
products.add(new Movie());
for (int index = 0; index < products.size(); index++) {
Product objProd = products.get(index);
objProd.display();
}
What will be displayed on the screen after the above code is executed?
Which of the following statements best describes inheritance in Java?
Explanation / Answer
Question 1 Answer) Inheritance in java is used to build classes with additional special attributes and metjods ither than its parent classe
Question 2 Answer) throws statement in java is used to throw an exception
Question 3 Answer) Shadowing
Question 5 Answer) extends
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.