What is the big class of Java?, Java senior programmer interview written examination classic Cai Yu

big class java java senior

In his previous work , I've interviewed a lot of job seekers , Found that there are many interviewers to Java Of  Class  I don't understand , The understanding is not in place , Have a superficial knowledge of , When it comes to using , I don't know how to use it .

I want to write an article about Java Class  The article , There are not so many professional terms , I hope to use popular language to put Java Of  Class  Make the concept clear , I understand Class after ,Java It's much easier to understand .

Class be prone to , Make sure you see it , Let's get familiar with one of the most fundamental concepts , What is a class? ?

What is a class? ?


This must be all the students who have studied object-oriented programming language should know , Here's a more formal description

A class is a collection of entities that share some common characteristics

For example, the following defines a Student class

class Student{

String name;

int age;

public void learn(){

System.out.println(“ Is learning ”);

}

public int getAge(){

return age;

}

public void hello(String message){

System.out.println(message);

}

}

All the students have a name , There are ages , To learn , These are the common characteristics of students

So since all students have some common characteristics , Then we Java( The same goes for other languages ) In language , Do all classes have common features ?

I don't understand ? All classes have common features ? Yes ? No mistake

Let's define another class Book, as follows

class Book{

private float price;

private String author;

}

All books have Price , Public characteristics such as authors ( And here for simplicity , The examples are as little code as possible )

therefore , Whether it's on top of it Student,Book class , still Java The built-in classes in languages, such as String class

All the classes , There are some commonalities :

  • All the classes , They all have a class name : Like the one above  StudentBookString class , Plus the package name , If the package name is com.test , So the names of these classes are

com.test.Student , com.test.Bookcom.test.String

  • All the classes , There are 0 One or more fields , Like the one above  name,age,price,author

  • All the classes , There are 0 One or more methods , Like the one above learn()

  • All the classes , There are modifiers , such as public,private,protected etc.

  • All the classes , There are 0 One or more static methods

  • And so on.

Class What is it ?


We know from the above analysis , All classes have some common features , So let's define a class , To describe these common features , Let's give this class a class name , It's called  Info

In fact, we have Info class , Namely java Medium Class,java Medium Class It's just a common class , It's no different from other classes . Don't believe me Class Definition

Is it a common class , Let's get rid of inheritance , Is that what happened next

public class Class {

}

It's just a common class , But the class name is also called Class, and java Keywords in class, It's just capitalized , Let me say that we shouldn't have called it Class, It should be called Type, There won't be so many misunderstandings , No one would have put Class,class The two are confused and confused .

In a word :Class It's a common class , This class describes the common features of all classes

Class What can a class do ?


understand Class Before class can do anything , Let's expand something else first

Now that we know , All classes have common features , We defined a name as Class To describe these common features

So is it the method of all classes , All class fields , Is there a common feature ?

answer Yes

Is it a bit confusing ? Don't be afraid of , It's simple , Take an example .

It's still up there Student,Book class ,

  • All class fields , They all have names .

such as Book Class price Field , Is its name "price"

  • All class fields , There are all types .

such as Book Class price Field , Its type is  float

  • All class fields , There are modifiers .

such as Book Class price Field , Its modifier is  private

So the fields of these classes have common features , We can also define a class to describe , This class is Field

《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 Full content open source sharing

Let's see JDK About China Field The definition of

Is it right? Class Similar to class ,Field Class is also a common class

Empathy , All the methods in the class , Is there a common feature ?

answer : Yes

  • Methods of all classes , They all have method names

such as Student Class getAge() Method , Its method name is  "getAge"

  • Methods of all classes , All have return value types

such as Student Class getAge() Method , Its return value is  int type

  • Methods of all classes , They all have parameters .( It's a special parameter )

such as Student Class hello(String message) Method , There is a parameter , The type of the parameter is, and the value is  String type

  • Methods of all classes , They all have embellishments .

such as Student Class getAge() Method , It's embellished with  public

So the common features of the methods of these classes , We can also define a class to describe , This class is Method

Let's take a look at JDK Defined in the

It's also a common class

From above you can , that Class Class is through Field and Method To describe the fields and methods in a class

Let's take a look JDK in Class Class , About Field and Method Members of

These arrays are used to hold fields or methods in a class .

Far away , Back to the beginning ,Class What can a class do ?

Now that we know through the above ,Class The common properties of all classes in the , So, are we through Class Know how many methods are in a class , How many fields are there , What is the name of each field , What is the type of each field , What is the method name of each method , A method has several parameters , wait

answer Is "yes"

How to get through Class I know what you're talking about ?

Writing code, of course , For example, when we run programs , Click a button , Print out the information of a class , It can be done

Class How to use ?


Now that we know Class What can I do ? Let's take a brief look at , How to use Class

How to use Class?

Class It's a common class , To use a normal class is to create an object , To use it

Very simple! , We create a Class The object of the object is OK , You can call all kinds of methods of the object

It's so easy to use

How to get a Class The object of ?

copyright:author[m0_ sixty-four million three hundred and eighty-four thousand t],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261536161021.html