Advanced inheritance abstract, interface -java

When creating an abstract class whose processing is not decided at this time Use ** abstract **

sample


	public abstract class Classicmusic {
	//Abstract class about classical music

	public abstract String getCountry();
	 //Abstract method to get the country of origin
	 //return Country of origin of composer
	 
	public abstract String[] getmusicList();
	 //Abstract method to get song list
	 //return List of representative songs

A class that implements even one abstract method ** must be an abstract class with abstract **. And the abstract class cannot be instantiated with new. Note) It is possible to implement non-abstract methods in abstract classes as well.

The abstract method is implemented by the ** child class to determine the content of the process. ** ** Use extends ** when inheriting ** abstract.

sample



	public class Bach extends Classicmusic {
	public String getCountry() {
		return "Germany";
	}

	public String[] getmusicList() {
	String[] mList = {"Goldberg Variations","Italian Concerto","English Suite"};
			return mpList;
		}

A class that inherits an abstract method must implement the abstract method. The content of the process is ** determined by the inherited class **. Determining the contents of a method that was undecided until then is called ** implementation **. If the inherited abstract method is not implemented, a compile error will occur.

This allows you to delegate the implementation to the inherited child class. In this way, by making the process that the content to be implemented is not decided but must be implemented as an abstract method, ** Can force implementation **.

Classes with a particularly high degree of abstraction can be treated as ** interfaces **.

As a condition to treat as an interface **-All methods are abstract methods ** ** · Has no fields ** Need to be

sample


	public abstract class Classicmusic {
	public abstract String getCountry();
	public abstract String[] getmusicList();
	}

//The interface can be as follows.

	public interface Classicmusic {
	String getCountry();
    String[] getmusicList();
	}

//If you want to implement the interface, use implements instead of extends.

	public class Bach implements Classicmusic 



Recommended Posts

Advanced inheritance abstract, interface -java
Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)
JAVA learning history interface inheritance
java (interface)
[Java] Inheritance
Java inheritance
[java] interface
Java inheritance
Advanced inheritance
java (inheritance)
[JAVA] Difference between abstract and interface
About Java interface
[Java] Class inheritance
java (abstract class)
interface and abstract
[Java] About interface
[Java] Functional interface
About java inheritance
About interface, java interface
[java] abstract class
Inheritance and interface.
[ev3 × Java] Interface, implementation and inheritance (event handling)
About Java functional interface
[Java] Overload / Override / Inheritance
Java abstract modifier [Note]
Callable Interface in Java
java standard functional interface
Summarize Java inheritance (Java Silver 8)
abstract (abstract class) and interface (interface)
JAVA learning history interface
About inheritance (Java Silver)
Java learning memo (interface)
[Java] Implicit inheritance memo
Java learning memo (inheritance)
About java abstract class
Interface / abstract class / override
[JAVA] What is the difference between interface and abstract? ?? ??
Use of Abstract Class and Interface properly in Java
[Java] Functional interface / lambda expression
Check Java9 Interface private methods
Java Development Basics-Practice ③ Advanced Programming-
Achieve Mixin-like implementation inheritance: Ruby module, Java interface, PHP trait
Java learning memo (abstract class)
Java starting from beginner, inheritance
Summary of "abstract interface differences"
[Java] What is class inheritance?
java (inheritance of is-a principle)
About abstract classes in java
Java abstract methods and classes
Access the network interface in Java
Muscle Java Object Oriented Day 2 ~ Inheritance ~
Difference between interface and abstract class
Java, abstract classes starting from beginners
[Java beginner] About abstraction and interface
Java, interface to start from beginner