공개 수업 라이브러리로 수업을 만들었습니다
Library books로 객체 생성 = new Library();
객체는 클래스의 메모리 표현입니다.
가장 중요한 개체 이름은 대문자로 되어 있으면 안 됩니다.
Java에서 객체를 생성하는 방법은 무엇입니까? {미정}
Java는 객체를 생성하는 5가지 방법을 제공합니다.
1 2 3 4 5 | Using new Keyword
Using clone () method
Using newInstance() method of the Class class
Using newInstance() method of the Constructor class
Using Deserialization
|
로그인 후 복사
코드:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public class Library
{
public static void main(String[] args)
{
Library books = new Library();
books.fiction();
Library librarian = new Library();
librarian.lending_books();
}
public void fiction()
{
System.out.println( "Book Name:Fiction books" );
}
public void lending_books()
{
System.out.println( "Librarian:Successfully lended the books" );
}
}
|
로그인 후 복사
출력:

위 내용은 확장 기능이 있는 Java 기본 프로그램의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!