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.
The source code is as follows...
Topic content: Please write a program to implement the following features: Users entered two data, if the two data are integers (ie, the numbers are composed), then output their subtraction operation ...
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...
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: ...
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...
(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: 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....
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...