Q6: What is the difference between a constructor and other common methods. What happens if you don't provide a constructor for a class. Can you call another constructor in one constructor? How to invoke the constructor of the parent class.
A6: The constructor must be the same as the class name, and there is no return value. The constructor is invoked only when the object is created, but the normal method can be invoked multiple times.
The normal method can have arbitrary names and can be invoked multiple times.
Q: What happens if you do not provide a constructor for a class.
A:java does not require you to explicitly provide a constructor for a class. If, in the declaration of a class, we do not provide any constructors, the compiler creates a default constructor with no parameters. If you explicitly declare a constructor in a class, the compiler will not automatically provide a default constructor.
Q: Can you call another constructor in one constructor?
A: You can, use this () syntax, as follows:
public Pet (int id) {
this.id = ID; ' This ' means this object
is public Pet (int ID, String type) {This
(ID); Calls constructor public Pet (int id)
this.type = type; ' This ' means this object
Q: How to invoke the constructor of the parent class.
A: Use Super () to invoke the parent class constructor as follows:
public specialpet (int id) {
super (ID); Must be the very of the statement in the constructor.
}
Q7: Please say something about the advantages of object-oriented programming languages:
A7: Object-oriented programming language directly represents objects in real life, such as automobiles, Jeeps, accounts, customers and so on. The features of Object-oriented programming languages, polymorphism, inheritance, and encapsulation make them very powerful. (Hint: Remember pie, representing polymorphic polymorphism, inheritance inheritance and encapsulation encapsulation, is the three pillars of OOPL).
Q8:oop is how to improve software development.
A8: The key benefit of using OOP is reusing previous work: using Inheritance and grouping. Real mapping to problem areas: object mapping to the real world, representing vehicles, customers, products, etc., using encapsulation. Modular Architecture: objects, systems, frameworks, etc. form the cornerstone of a large system.
The advantages we've listed also bring in "higher quality" and "less development time". If 90% of the new applications are made up of these proven components, only 10% of the coding begins with 0.