Instantiating a subclass object, what does instantiating a class object mean?

Updated on technology 2024-05-15
7 answers
  1. Anonymous users2024-02-10

    Just write it like this.

    public class a

    public static class subparent extends parent{

    public subparent(){

    Call the constructor of 2");

    public static void main(string args)

    subparent s=new subparent();

  2. Anonymous users2024-02-09

    public class parent {public parent(){

    Call the constructor of 1");

    public static void main(string args) {

    subparent s=new subparent();This sentence is wrong, I don't know why.

    parent s=new subparent();Polymorphism.

    ddd");

    class subparent extends parent{ There can only be one public class in a class.

    public subparent(){

    Call the constructor of 2");

  3. Anonymous users2024-02-08

    Write the mian method to the parent class.

  4. Anonymous users2024-02-07

    Visualize a class, and realize the function of the class through the instance of the class, which is the object. Because classes are abstract, you need to instantiate objects in order to use them.

    The student class is a subclass of person, so in terms of data structure relationship, student not only has all the characteristics of person, that is, the parent class, but also has its own unique properties. In the storage area, the distribution of students is that the beginning of the area is all the data of the parent person class, and then the unique properties of the student class itself. So their relationship is that the data of the child class is to add some features of its own to the data of the parent class.

    In this case, when we use a child class to instantiate an object, then the object also has all the characteristics of the parent class, so it is perfectly fine if we type the object of the child class to the object of the parent class, because the object of the child class has all the characteristics of the parent class.

    The person p = new student() statement is equivalent to implicitly declaring a child class object and then implicitly converting it to the parent class. So p here should be the object of the parent class person. The advantage of this is that for example, you declare an interface or abstract class, and then you want to use it to instantiate the object, but the abstract class cannot be instantiated directly, so you need to rely on the subclass to help.

  5. Anonymous users2024-02-06

    class void normal person.

    class void superman extends normal people.

    This normal person is a class that describes the characteristics of a person, all the characteristics. But it's just a concept, not a specific person.

    var normal person Huang 3 = new normal person (); Instantiating people, Huang San is an example of people. Huang San has the characteristics of a normal person and all the behaviors that are in line with normal people. refers to a real person.

    var normal person 李四=new normal person();

    var spider-man=new Superman(); Instantiation of Superman, Spider-Man is an instance of Superman, which not only has the characteristics and behaviors of normal people, but also has characteristics and behaviors that normal people do not have.

    At this point, you can control the yellow.

    Three, Li Si or Spider-Man.

    Huang San unfortunately had a car accident, and at this time we can use the number of Huang San's hands to achieve the goal. Huang San. Number of lots = 1;

    Unfortunately, there is a big **, and there is only one person on the foot of all people in the world. We can modify the number of feet. One is a normal person.

    Number of feet = 1. At this time, whether it is Huang San, Li Si, or Superman, there is only one foot. Later, when a child is born (a normal person, for example, a normal person) has only one foot;

    The second is, Huang San. Number of feet = 1. John doe. Number of feet = 1. If there is still Zhang Wu, Zhao Liu... You also have to assign values to them. But the child born later (instantiating a normal person) still has two legs.

    That's the difference between a class and an instance reference. Of course, in this program**, you can change the number of Huang San, Li Si or Superman's feet individually, but you can't make all normal people's hands one at once, unless it's for a loop. Fun anti?

  6. Anonymous users2024-02-05

    For example, house is a type.

    A house is an instance of a house class, and the house number is a reference to the instance object.

    Create an example of a class.

    1 Allocate memory (in the same neighborhood where the house is built).

    2 Get the address of the memory, i.e., the reference (house number).

  7. Anonymous users2024-02-04

    1. Use the new statement to create a bai

    objects, which is the most common way to create objects.

    2. Return the object DAO through the factory method, for example: string str = ;

    3. Use the reflection method to call the newinstance() instance method of the or weight class. For example: object obj ="").newinstance();

    4. Call the clone() method of the object.

    5. Through the IO stream (including deserialization), such as using deserialization, call the readobject() method of the object.

Related questions
9 answers2024-05-15

There must be a certain amount of pressure, not too tight or too loose, and you must learn to adjust, so that you can cope with the problems you have to face, which is conducive to physical and mental health. >>>More