This is the 22nd day of my participation in the August More Text Challenge

Difficulty level: Easy

The program

Program a

1) What is the output of the following program?

class Derived
{
	protected final void getDetails(a)
	{
		System.out.println("Derived class"); }}public class Test extends Derived
{
	protected final void getDetails(a)
	{
		System.out.println("Test class");
	}
	public static void main(String[] args)
	{
		Derived obj = newDerived(); obj.getDetails(); }}Copy the code

A) derived class B) test class C) runtime error d) compile error

Click here to jump to the answer


Program 2

2) What is the output of the following program?

class Derived
{
	public void getDetails(String temp)
	{
		System.out.println("Derived class "+ temp); }}public class Test extends Derived
{
	public int getDetails(String temp)
	{
		System.out.println("Test class " + temp);
		return 0;
	}
	public static void main(String[] args)
	{
		Test obj = new Test();
		obj.getDetails("HY"); }}Copy the code

a) Derived class HY

b) Test class HY

c) Compilation error

d) Runtime error

Click here to jump to the answer


Application of three

3) What is the output of the following program?

class Derived
{
	public void getDetails(a)
	{
		System.out.println("Derived class"); }}public class Test extends Derived
{
	protected void getDetails(a)
	{
		System.out.println("Test class");
	}
	public static void main(String[] args)
	{
		Derived obj = new Test(); // line xyzobj.getDetails(); }}Copy the code

a) Test class

b) Compilation error due to line xyz

c) Derived class

d) Compilation error due to access modifier

Click here to jump to the answer


Application of four

4) What is the output of the following program?

import java.io.IOException;

class Derived
{
	public void getDetails(a) throws IOException //line 23
	{
		System.out.println("Derived class"); }}public class Test extends Derived
{
	public void getDetails(a) throws Exception //line 24
	{
		System.out.println("Test class");
	}
	public static void main(String[] args) throws IOException //line 25
	{
		Derived obj = newTest(); obj.getDetails(); }}Copy the code

A) compilation error due to line 23 b) compilation error due to line 24 c) compilation error due to line 25 d) all of the above

Click here to jump to the answer


Application of five

5) What is the output of the following program?

class Derived
{
	public void getDetails(a)
	{
		System.out.printf("Derived class "); }}public class Test extends Derived
{
	public void getDetails(a)
	{
		System.out.printf("Test class ");
		super.getDetails();
	}
	public static void main(String[] args)
	{
		Derived obj = newTest(); obj.getDetails(); }}Copy the code

A) Test class Derived class B) Derived class Test class C) compiler error d) runtime error

Click here to jump to the answer


The second part is the output and analysis of the program


Output and parsing

Program one output

The answer:

(d)Copy the code

Description:

Final and static methods cannot be overridden.


Program two output

The answer:

(c)Copy the code

Description:

Overriding methods must have the same signature, including parameter lists and return types


Program three output

The answer:

(d)
Copy the code

Description:

Overriding methods cannot have more stringent access modifiers


Procedure 4 Answer

Answer:

(b)
Copy the code

Description:

Exceptions thrown by override methods should not be new or more extensive checked exceptions. In the above code, Exception is a more extensive check Exception class than IOException, so this can lead to a compilation error.


Procedure 5 Answer

Answer:

(a)
Copy the code

Description:

The super keyword is used to explicitly call overriding methods of subclasses.


That’s all for this article

Related articles:

Java program Java exercises 】 【 | at the output of the first set of (analysis) the output of the Java program Java exercises 】 【 | second (analysis) the output of a Java program | Java exercises 】 【 a third (including parsing) [Java exercises] | at the output of the Java program Fourth set (including the parse) the output of a Java program | Java exercises 】 【 5 sets (including parsing) the output of the Java program Java exercises 】 【 | 6 sets (including parsing) the output of a Java program | Java exercises 】 【 7 sets (including parsing) Java Java exercises 】 【 Program’s output | 8 sets (including parsing) the output of a Java program | Java exercises 】 【 9 sets of (including the parse) the output of a Java program | Java exercises 】 【 10 sets (recycling) the output of a Java program | Java exercises 】 【 11 sets of (including parsing) The output of a Java program | Java exercises 】 【 12 sets (including parsing) the output of a Java program | Java exercises 】 【 13 sets (set) the output of a Java program | Java exercises 】 【 14 sets (constructor) [Java exercises] | at the output of the Java program 15 sets of (internal) the output of a Java program | Java exercises 】 【 16 sets (threads) the output of a Java program | Java exercises 】 【 17 sets of (including parsing)

I’ve been writing tech blogs for a long time and this is one of my tech posts/tutorials. Hope you like it! Here is a summary of all my original and works of source: GitHub, and this is my recently just built blog: Haiyong. Site, there is no content, put some HTML games, interested can try, source code can be their own F12 copy, or directly find me to.

If you really learn something new from this article, like it, bookmark it and share it with your friends. 🤗 and finally, don’t forget ❤ or 📑.