Home > Back-end >  Java object-oriented
Java object-oriented

Time:09-16

1, write a class Student no arguments constructor and two int type has a constructor, and the main method invokes the
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 title

CodePudding user response:

His subject yourself

CodePudding user response:

Is not I won't do want to ask you

CodePudding 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 skilled

CodePudding 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 the

CodePudding user response:

Abstract classes and interfaces difference between
The 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:

reference any time efforts won't be late reply on the eighth floor:
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:
Can'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)

Interface of this story is very interesting: in a broad sense, any interface is a kind of thing with another thing interaction mechanism used, for example, the TV remote is a remote interface, the dog can understand and execute commands, which means that the dog voice (control) interface, above all, we can say that the interface is a standard way of interacting, two things only if both sides know this standard, when one person commands the dog "sit", his or her command is part of the "dog" voice control interface, if the dog to obey the command, then we say interface is supported by the dog,

CodePudding user response:

Baidu many answers
  • Related