/*

     Formal parameters :

         Reference type

Interface : What you need is an implementation class object for the interface

It's nothing at this time , It's similar to the explanation of abstract classes .

*/

interface Love {
public abstract void love();
} class LoveDemo {
public void method(Love l) {
l.love();// If you see that the reference type in a method is an interface type , What should be passed here is the implementation class object of the interface .
}
} // Define specific class implementation interface , The implementation class of this interface
class Teacher implements Love {
public void love() {
System.out.println(" Formal parameters are interface types ");
}
} class TeacherTest {
public static void main(String[] args) {
// demand : test LoveDemo Class love() Method
LoveDemo ld = new LoveDemo();
Love l = new Teacher();// It belongs to polymorphism
ld.method(l);
Teacher t = new Teacher();
ld.method(t);
}
}
/*
return type
Reference type :
Interface : What is returned is the object of the implementation class of the interface
*/
// Define a hobby interface
interface Love {
public abstract void love();
} class LoveDemo {
public Love getLove() { return new Teacher();// Anonymous object
}
} // Define specific class implementation interface
class Teacher implements Love {
public void love() {
System.out.println(" The return value type is the interface type ");
}
} class TeacherTest2 {
public static void main(String[] args) {
LoveDemo ld = new LoveDemo();
Love l = ld.getLove(); // It's polymorphic
l.love();// Can be called
}
}

《java Season one 》 Object oriented ( In depth study of formal parameter and return value problem 3) More articles about

  1. JAVA Season one (mooc- note )

    Notes related information /** * @subject < Learning and entrepreneurship > Homework 1 * @author Trust tube 1142 class 201411671210 Lai Junjie * @className <JAVA Season one ...

  2. Java Season one —— Since then, I have devoted myself to Java??

    Job hunting is over . The final work , and java Closely related , It's also a mistake , But it's all software development , It's all right , But in the future, the focus must be java here ,php If you have a chance, you will continue to learn , So beautiful ~ Java The first season of development   One . Jane ...

  3. 10-02 Java The problem of formal parameter and return value is deeply studied , Chain programming

    The problem of formal parameter and return value : 1: The problem of formal parameter and return value ( understand ) (1) Formal parameters : Class name : Objects of this class are required Abstract class name : Subclass objects of this class are required The interface name : You need an implementation class object for this interface (2) return type : Class name : It's time to go back ...

  4. 《java Season one 》 Object oriented ( Talk about interfaces )

    There are interfaces in the software , The interface here is quite different from that in hardware . The interface is introduced here without considering JDK8 New features (JDK8 At first, there can be non abstract methods in the interface , Introduce JDK8 The new features may be finished in the first season !) Or directly into the interface ...

  5. 《java Season one 》 Object oriented ( How to use help documents )

    1: Open help document 2: Click to display , Find the index , See the input box 3: Know who you're looking for ? With Scanner give an example 4: Enter... In the input box Scanner, And then go back 5: Look at the bag java.lang The classes under the package do not need to import the package , Everything else ...

  6. 《java Season one 》 Object oriented ( Member method )

    /* Class composition : Member variables , Member method A new member has been added : Construction method . I'll talk about it later ( Class composition ): Member variables Construction method Member method According to the return value : void type Not void type Formal parameters : The space parameter method Non null parameter method ...

  7. 《java Season one 》 Object oriented (private The concept of keyword and encapsulation )

    /* Define a student class : Member variables :name,age Member method :show() Method In the process of using this case , A problem has been identified : Assign values to member variables through objects , You can assign some illegal data . for example :name You assigned a 3 ...

  8. Java Season one

    For class network :http://www.imooc.com/learn/85 Java Introduction season one 1.Java Development environment and IDE Use : 2. Variables and constants 3. Common operators 4. Flow control statement 5. Array : Use Ar ...

  9. 《java Season one 》 And Arrays Quasi Prequel ( Sort the cases in order to find the problems that should be paid attention to )

    According to the sorting algorithm , Can solve some small cases . Examples are as follows : /* * Sort the characters in a string . * give an example :"dacgebf" * result :"abcdefg" * * analysis : ...

Random recommendation

  1. A little cold rain Java Multithreading in ( One )

    Before we talk about multithreading , We have to understand what multithreading is ? And a lot of people compare processes to threads . Processes and threads process : Processes are the foundation of the operating system architecture , It's a program execution , Is a program and its data in the process of sequential execution of the activities , It's the program ...

  2. SmohanTimeLine.js Cool timeline effect

    Show address Download this The source of the original text is One . Parameter description item : '.item', // Project elements top : 30, // The distance from the next line pointWidth : 22, // Time point width cornerWidt ...

  3. JS Script collection ( Some practical functions )

    One . share onload event The name of this function is addLoadEvent, It is from Simon Willison Compiling . It has only one parameter : The name of the function to execute when the page is loaded . Here is addLoadEvent Letter ...

  4. 【 The Internet 】IP Address format translation (htonl、ntohl;inet_addr、inet_ntoa)

    1.htonl () and ntohl( ) u_long PASCAL FAR ntohl (u_long netlong); u_short PASCAL FAR ntohs (u_short nets ...

  5. java note -- About thread deadlocks

    About thread deadlocks What is a deadlock : When writing multithreading , We must pay attention to the use of resources , If two or more threads have different resources , At the same time, the other party needs to release resources to continue running , A deadlock will occur . Simply speaking : A deadlock is when one or more ...

  6. Ruby Class

    Class definition : class Class name Class definition end ※ The class name starts with a capital letter !!! Construction method (initialize) Class name call new Method time , One way to trigger . def initialize(my_name = & ...

  7. JS Learning notes --4--- Operator

    1.JS The operators included in are : Unary operator . Binary operator . Ternary operator . Arithmetic operator . Relational operator . Logical operators . An operator . Assignment operator . Other operators, etc . 2. expression : In short, it's just a sentence of code ( Semicolons separate ), The interpreter will turn it over ...

  8. Use build_opener Customize opener

    Use build_opener Customize opener, The advantage of this method is that it is convenient to expand the function . import urllib.request import http.cookiejar def makeMyO ...

  9. mysql Data type alias reference

    To facilitate the use of code written for SQL implementations from other vendors, MySQL maps data ty ...

  10. PythonProject(1)vim Of Hustoj plug-in unit

    I'm going to write one vim Plug in for , perhaps emacs Plug in for . You can play games in the editor , see rank, Cross code . In short, it's equivalent to a desktop version of hustoj This is the product of a brain hole that we had last semester , I learned yesterday Python The reptiles of , I found this thing very real ...