Java EE interview Bible translation (2)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.