2, the difference between method overloading and rewrite
3, briefly describes the characteristics of the final and the static keyword
4, use two methods to define a String type of two-dimensional array and assignment
5, the difference between abstract class and interface
CodePudding user response:
little brother is in the record the titleCodePudding user response:
His subject yourselfCodePudding user response:
Is not I won't do want to ask youCodePudding user response:
On baidu, a lot of people will bother to speak not also said not to come out, ask veteran they may can't answer, but use one time than a skilledCodePudding user response:
Interface
Package demo;
Public interface Trainee {
Void study ();
}
An abstract class
Package demo;
The import static Java. Lang. System. *;
Public abstract class Person {
Protected final String school="Home College";
The static String domitory="2 bl3";
Public void eat () {
Out.println (" Eats shit. ");
}
Public void sleep () {
Out.println (" Sleeps like a pig!" );
}
Public void writeInfo () {
Out.println (school);
WriteAge ();
WriteHeight ();
}
Protected the abstract void writeAge ();
Protected the abstract void writeHeight ();
}
Student
Package demo;
The import static Java. Lang. System. *;
Public class Student extends the Person implements Trainee {
Private int the age;
Private int height;
Private String course="College Engligh One ';
Public Student () {
Age=21;
Height=159;
}
Public Student (int the age, int height) {
this.age=age;
This. Height=height;
}
@ Override
Public void study () {
Out.println (" Studies "+ course);
}
Public static void main (String [] args) {
Out.println (Person. Domitory);
Trainee studentA=new Student ();
StudentA. Study ();
The Person studentB=new Student ();
StudentB. Eat ();
StudentB. Sleep ();
Student studentC=new Student (22, 165);
StudentC. WriteInfo ();
StudentB. Sleep ();
}
@ Override
Protected void writeAge () {
Out.println (" My age is "+ age);
}
@ Override
Protected void writeHeight () {
Out.println (" My height is "+ height);
}
}
CodePudding user response:
Baidu once, all is to explain theCodePudding user response:
Abstract classes and interfaces difference betweenThe same:
1. Don't create objects
2. Can write abstract methods
Different:
1. In the abstract class can have the abstract method, the interface is allowed to have a default after JDK1.8 modified method, this is only an abstract method before
2. Interface without construction method, construction code block, the static block
3. All of the attributes of interface default to public static final modify
4. All the methods in the interface default to public the abstract modifier
CodePudding user response:
Method overloading:1. In the same class;
2. The method name, parameter different
3. Different parameters including, number of parameters is different, different parameter type, parameters in a different order.
4. The method overloading and return values, modifier, if abnormal, the parameter name has nothing to do,
5. A constructor can be overloaded
Rewrite:
1. The inheritance relationship, parents and children consistent method name
2. Parents and children method returns the same value
3. The parent class private methods can't rewrite
4. The parent class is static, subclasses override must also be static
5. A constructor cannot be rewritten,
Abstract:
No special class instance, equivalent to a function template
Interface:
Don't define variables, cannot be instantiated, but multiple inheritance, methods are abstract method, equivalent to a standard definition, use the class must implement the interface of the interface methods (except abstract class)
CodePudding user response: