Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Class Creation | Classes
Java Extended
course content

Зміст курсу

Java Extended

Java Extended

1. Deep Java Structure
2. Methods
3. String Advanced
4. Classes
5. Classes Advanced

bookClass Creation

Class Syntax

The syntax for creating a class is quite simple. Let's take a look at an example with the class Person:

java

Person

copy
123
class Person { }

This is all it takes to create a class. However, it will be useless to us if it's empty. Therefore, we should add fields to it. Let's assume that our person has a name, gender, and age:

java

Person

copy
12345
class Person { String name; String gender; int age; }

And now, let's write a method that allows our Person to report their name and age:

java

Person

copy
123456789
class Person { String name; String gender; int age; void introduce() { System.out.println("Hi, my name is " + name + " and I am " + age + " years old!"); } }

Завдання

Great! Now your task is to create two objects of the Person class in the main method. One will be named Bob and will be 30 years old, and the other will be named Alice and will be 27 years old. Then, use the introduce() method on each person to have them introduce themselves.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 4
toggle bottom row

bookClass Creation

Class Syntax

The syntax for creating a class is quite simple. Let's take a look at an example with the class Person:

java

Person

copy
123
class Person { }

This is all it takes to create a class. However, it will be useless to us if it's empty. Therefore, we should add fields to it. Let's assume that our person has a name, gender, and age:

java

Person

copy
12345
class Person { String name; String gender; int age; }

And now, let's write a method that allows our Person to report their name and age:

java

Person

copy
123456789
class Person { String name; String gender; int age; void introduce() { System.out.println("Hi, my name is " + name + " and I am " + age + " years old!"); } }

Завдання

Great! Now your task is to create two objects of the Person class in the main method. One will be named Bob and will be 30 years old, and the other will be named Alice and will be 27 years old. Then, use the introduce() method on each person to have them introduce themselves.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 4
toggle bottom row

bookClass Creation

Class Syntax

The syntax for creating a class is quite simple. Let's take a look at an example with the class Person:

java

Person

copy
123
class Person { }

This is all it takes to create a class. However, it will be useless to us if it's empty. Therefore, we should add fields to it. Let's assume that our person has a name, gender, and age:

java

Person

copy
12345
class Person { String name; String gender; int age; }

And now, let's write a method that allows our Person to report their name and age:

java

Person

copy
123456789
class Person { String name; String gender; int age; void introduce() { System.out.println("Hi, my name is " + name + " and I am " + age + " years old!"); } }

Завдання

Great! Now your task is to create two objects of the Person class in the main method. One will be named Bob and will be 30 years old, and the other will be named Alice and will be 27 years old. Then, use the introduce() method on each person to have them introduce themselves.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Class Syntax

The syntax for creating a class is quite simple. Let's take a look at an example with the class Person:

java

Person

copy
123
class Person { }

This is all it takes to create a class. However, it will be useless to us if it's empty. Therefore, we should add fields to it. Let's assume that our person has a name, gender, and age:

java

Person

copy
12345
class Person { String name; String gender; int age; }

And now, let's write a method that allows our Person to report their name and age:

java

Person

copy
123456789
class Person { String name; String gender; int age; void introduce() { System.out.println("Hi, my name is " + name + " and I am " + age + " years old!"); } }

Завдання

Great! Now your task is to create two objects of the Person class in the main method. One will be named Bob and will be 30 years old, and the other will be named Alice and will be 27 years old. Then, use the introduce() method on each person to have them introduce themselves.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 4. Розділ 4
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt