Classes and instances Java for beginners

environment ・ MacBook pro ・ IntelliJ IDEA CE

I will post it for output while learning Java.

About classes and instances

Class: Design document, skeleton Instance: An entity created based on a class

You have been instructed by your boss to build a human world care robot and one of its sister robots from a mass-produced cat robot factory.

My boss gave me detailed data.

About human world care robots
Name: Dora Emon
Color: blue
Gender: Male

About Dora Emon's sister robot
Name: Dorami-chan
Color: pink
Gender: Woman

Create the above two bodies.

Looking at the detailed data, three elements are required. ・ Name ・ Color ・ Gender (sex)

First, complete the class as instructed by your boss.

Robot.java



class Dora {
    String name;
    String color;
    String sex;

    Robot(String name, String color , String sex){
        this.name = name;
        this.color = color;
        this.sex = sex;
    }

    String sayBox(){
        return name +"is. color is,"+color+"is. what is your gender"+sex+"is.";
    }
}

Now you have a class.

Next, create an instance (details).

RobotFactory.java



public class RobotFactory {
    public static void main(String[] args){
        Dora robota = new Dora("Dora picture mon","Blue","Man");
        System.out.println(robota.sayBox());

        Dora roboco = new Dora("Dora Minoru","pink","woman");
        System.out.println(roboco.sayBox());
    }
}


I will output it. スクリーンショット 2020-10-14 14.57.28.png

It's a success. : relaxed:

Recommended Posts

Classes and instances Java for beginners
java (classes and instances)
[For beginners] Explanation of classes, instances, and statics in Java
Kantai Collection Java # 1 Classes and Objects [For Beginners]
Java for beginners, expressions and operators 1
Java for beginners, expressions and operators 2
Java programming (classes and instances, main methods)
java classes, instances, objects
About classes and instances
Ruby classes and instances
Java debug execution [for Java beginners]
[Java] Basic statement for beginners
[Java] Generics classes and generics methods
Consideration about classes and instances
About Ruby classes and instances
Creating Ruby classes and instances
Java abstract methods and classes
Java application for beginners: stream
Java while and for statements
Java classes and instances to understand in the figure
List of frequently used Java instructions (for beginners and beginners)
[For beginners] Summary of java constructor
Java, abstract classes starting from beginners
Rock-paper-scissors game for beginners in Java
[For beginners] Run Selenium in Java
Writing code with classes and instances
Organize classes, instances, and instance variables
Java generics (defines classes and methods)
[For Java beginners] About exception handling
Learn Java with "So What" [For beginners]
[Java] for Each and sorted in Lambda
Memorandum (Ruby: Basic Grammar: Classes and Instances)
JAVA learning history abstract classes and methods
[Java] Proxy for logging SQL and SQL results
Write code using Ruby classes and instances
For JAVA learning (2018-03-16-01)
2017 IDE for Java
Java and JavaScript
XXE and Java
Java for statement
Getting Started with Java_Chapter 8_About Instances and Classes
I compared classes and instances with worldly things
Review notes for Java 1.7 and later file copies
Effective Java 3rd Edition Chapter 4 Classes and Interfaces
[Java] Personal summary of classes and methods (basic)
I studied for 3 weeks and passed Java Bronze
A collection of simple questions for Java beginners
[Introduction to Java] Basics of java arithmetic (for beginners)
Let's use Java New FileIO! (Introduction, for beginners)
[Java] for statement, while statement
Getters and setters (Java)
About products using crud processing and devise (for beginners)
[Java] Thread and Runnable
Sample (Java) for OAuth 2.0 authentication and access token acquisition
HashMap and HashSet classes
[Java] Package for management
[For beginners] Quickly understand the basics of Java 8 Lambda
Java true and false
[Java] for statement / extended for statement
String literals and instances
[Java] String comparison and && and ||