Write a program, implement the following features:

tags: Java language program design  java  interface  Polymorphism  Design Patterns  spring

Note that only one B.java file can be created, write a declaration class A, then declare class B
Write an abstract class A, with an abstract method Method1, and a non-abstract method Method2, functionality is printed Class a method2, both public.
Write class B inheritance A. With two specific methods Method1 and Method2, the former prints Class B Method1, the latter first call method method1, then print method Class B Method2.
The main function is also included in class B, which is A obj = new b (); obj.method2 (); what is the result of run? Explain that OBJ is the parent class or a sub-class object?
A.java

public abstract class A{
	public abstract void method1();
	public void method2() {
		System.out.println("class A method2");
		
	}
}

B.java

public class B extends A {
	@Override
	public void method1() {
		// TODO Auto-generated method stub
		System.out.println("class B method1");
	}
	public void method2() {
		method1();
		System.out.println("class B method2");
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		A obj=new B();
		obj.method2();
	}

}

operation result:

The parent class object, the subclass expands the object.

Intelligent Recommendation

Design the GUI interface program to achieve the following features

Familiar with the container assembly, basic components in graphical user interface programming. Design the GUI interface program to implement the following features: 1) Create a JFRAME window that can...

Python Programming Basis Section 7 Programming Exercises Please write a program to complete the following features: Enter a file path to output the file extension.

Topic content: Please write the program to complete the following features: Enter a file path to output the file extension. Input format: A file path. Output format: File extension. Enter the sample: ...

More Recommendation

(ArrayIndexoutofboundsexception is abnormal) Write a program that meets the following requirements:

Create an array that consists of 100 randomly selected integers Prompt the user into the subscript of the array and display the corresponding element value. If the specified subscript is off, the mess...

Use character stream and and GUI classes to implement the following features

(1) Design graphical interface, at least a text class control class. Receive the name, student number, grade from the keyboard, and save it to the text file, repeat. (2) Read the results of each stude...

Python: Using the FOR loop writing program to implement the following features: calculate 1-1 / 3 + 1 / 5-1 / 7 + ...- 1/99 + ..., the result retains 2 decimals.

Python: Use the for loop writing program to implement the following features: calculate 1-1 / 3 + 1 / 5-1 / 7 + ... -1 / 99 + ..., the result retains 2 decimals....

Python Programming Foundation Chapter II Programming Exercise 2 Using the for loop writing program to implement the following features: Calculate 1-1 / 3 + 1 / 5-1 / 7 + ...- 1 / (2 * n-1).

1 Using the For loop writing program to implement the following features: calculate 1-1 / 3 + 1 / 5-1 / 7 + ...- 1/99 + ..., the result retains 2 decimals. (2 minutes) Topic: Using the for loop writin...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top