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

Contenido del Curso

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!"); } }
Tarea
test

Swipe to show code editor

Alice wants to find a friend within a specific age range (25 - 30, inclusive). You need to write a program that checks whether Bob meets Alice's criteria. If Bob's age falls within the specified range, the program should return true; otherwise, it should return false.

  1. In the main method, you need to pass the correct object as the first parameter to the findFriend method.
  2. In the findFriend method, compare the age of the passed object with the specified age range (25 - 30).
  3. If the object falls within the age range, return true; otherwise, return false.
  4. To display the result on the screen, use the foundFriend variable, which stores the result of the search.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 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!"); } }
Tarea
test

Swipe to show code editor

Alice wants to find a friend within a specific age range (25 - 30, inclusive). You need to write a program that checks whether Bob meets Alice's criteria. If Bob's age falls within the specified range, the program should return true; otherwise, it should return false.

  1. In the main method, you need to pass the correct object as the first parameter to the findFriend method.
  2. In the findFriend method, compare the age of the passed object with the specified age range (25 - 30).
  3. If the object falls within the age range, return true; otherwise, return false.
  4. To display the result on the screen, use the foundFriend variable, which stores the result of the search.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 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!"); } }
Tarea
test

Swipe to show code editor

Alice wants to find a friend within a specific age range (25 - 30, inclusive). You need to write a program that checks whether Bob meets Alice's criteria. If Bob's age falls within the specified range, the program should return true; otherwise, it should return false.

  1. In the main method, you need to pass the correct object as the first parameter to the findFriend method.
  2. In the findFriend method, compare the age of the passed object with the specified age range (25 - 30).
  3. If the object falls within the age range, return true; otherwise, return false.
  4. To display the result on the screen, use the foundFriend variable, which stores the result of the search.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

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!"); } }
Tarea
test

Swipe to show code editor

Alice wants to find a friend within a specific age range (25 - 30, inclusive). You need to write a program that checks whether Bob meets Alice's criteria. If Bob's age falls within the specified range, the program should return true; otherwise, it should return false.

  1. In the main method, you need to pass the correct object as the first parameter to the findFriend method.
  2. In the findFriend method, compare the age of the passed object with the specified age range (25 - 30).
  3. If the object falls within the age range, return true; otherwise, return false.
  4. To display the result on the screen, use the foundFriend variable, which stores the result of the search.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 4. Capítulo 4
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt