Interview Questions-java basics-Object oriented parts

Source: Internet
Author: User

1. What is a Java virtual machine? Why is Java called a "platform-agnostic programming language"?

A Java Virtual machine is a virtual machine process that can execute Java bytecode. The Java source file is compiled into a bytecode file that can be executed by the Java virtual machine.
Java is designed to allow applications to run on arbitrary platforms without requiring programmers to rewrite or recompile each platform individually. The Java Virtual machine makes this possible because it knows the instruction length and other features of the underlying hardware platform.

What is the difference between 2.JDK and JRE?

The Java Runtime Environment (JRE) is the Java virtual machine that will execute the Java program. It also contains the browser plug-in needed to execute the applet. The Java Development Kit (JDK) is a complete Java software development package that includes a JRE, a compiler, and other tools (such as the Javadoc,java debugger) that enable developers to develop, compile, and execute Java applications.

3. What does the "static" keyword mean? Is it possible to overwrite (override) a private or static method in Java?

The "static" keyword indicates that a member variable or a member method can be accessed without an instance variable of the class to which it belongs.
The static method in Java cannot be overridden because method overrides are dynamically bound based on the runtime, while the static method is statically bound at compile time. The static method is not relevant to any instances of the class, so it is conceptually not applicable.

4. Can I access non-static variables in the static environment?

The static variable belongs to the class in Java, and it has the same value in all instances. Static variables are initialized when the class is airborne into Java virtual. If your code tries to access a non-static variable without an instance, the compiler will give an error because the variables have not been created yet and are not associated with any instances.

What are the data types supported by 5.Java? What is auto-unboxing?

The 8 basic data types supported by the Java language are:
Byte
Short
Int
Long
Float
Double
Boolean
Char
Auto-Boxing is a conversion of the Java compiler between the base data type and the corresponding object wrapper type. For example: Convert int to integer,double into double, and so on. The reverse is automatic unpacking.

what does the method overlay (overriding) and method overloading (overloading) in 6.Java mean? method Overloads in Java occur when the same class has two or more methods with the same name but different parameters. In contrast, the method overrides the method that the subclass redefined the parent class. Method overrides must have the same method name, parameter list, and return type. The override may not restrict access to the methods it covers. in 7.Java, what is a constructor function? What is a constructor overload? What is a copy constructor? when a new object is created, the constructor is called. Each class has a constructor function. The Java compiler creates a default constructor for this class in cases where the programmer does not provide a constructor for the class.
Constructor overloading and method overloading are similar in Java. You can create multiple constructors for a class. Each constructor must have its own unique argument list.
Java does not support copy constructors like in C + + because Java does not create a default copy constructor if you do not write the constructor yourself. does 8.Java support multiple inheritance? classes in Java do not support multiple inheritance, only single inheritance (that is, a class has only one parent). However, the interface in Java supports multiple inheritance, that is, a sub-interface can have multiple parent interfaces. (The function of the interface is to extend the function of the object, a sub-interface inherits multiple parent interfaces, indicating that the sub-interface extends several functions, when the class implements the interface, the class expands the corresponding function). 9. What is the difference between an interface and an abstract class? Java provides and supports the creation of abstract classes and interfaces. Their implementations have something in common, and the difference is that:
All methods in an interface are implicitly abstract. Abstract classes can contain both abstract and non-abstract methods.
A class can implement many interfaces, but only one abstract class is inherited
Classes can not implement all methods of abstract classes and interface declarations, and of course, in this case, the class must also be declared abstract.
An abstract class can implement an interface without providing an interface method implementation.
The variables declared in the Java interface are final by default. An abstract class can contain non-final variables.
The member functions in the Java interface are public by default. The member functions of an abstract class can be private,protected or public.
An interface is absolutely abstract and cannot be instantiated. An abstract class can also not be instantiated, but it can be called if it contains the main method.
You can also refer to the differences between abstract classes and interfaces in JDK810. What is value passing and reference passing? A value pass is a basic variable, passing a copy of the variable, and changing the copy does not affect the original variable. A reference pass is generally for an object type variable, passing a copy of the object's address, not the original object itself. So manipulating the Reference object changes the original object. It is generally assumed that the delivery within Java is a value pass. 

Interview Questions-java basics-Object oriented parts

Related Article

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.