How to call method from another class?

How to call method from another class?

So I'm a rookie at OOP and I am currently having trouble using a function from another method. The class below is the main class for a card game. Here it creates a deck of cards by creating an object from the Game class. It then starts the game with the created deck and should print the size of the deck.

So I'm a rookie at OOP and I am currently having trouble using a function from another method. The class below is the main class for a card game. Here it creates a deck of cards by creating an object from the Game class. It then starts the game with the created deck and should print the size of the deck.

public class Run {

public static void main(String[] args) {

Game game;
System.out.println("Welcome!");
play = true;
while (play) {
    game = new Game(3); //Create deck of card based on number of ranks given
    game.play(); //Starts the game with deck of card
}

}

The class below is the Game class. When the game starts it should print the size of the deck created.

public class Game {
public Game(int ranks)
{
    Deck Main = new Deck(ranks);
}
public static void play()
{
    System.out.println(Main.size()); //Where the error occurs
}

The class below is the Deck class where it actually creates the deck and has a method that returns the size of that deck.

public class Deck {

private ArrayList<Card> cards;

public Deck(int range) { cards = new ArrayList<Card>(); for (int i=1; i<=range; i++) { Card card = new Card(1, i); Card card2 = new Card(2, i); Card card3 = new Card(3, i); Card card4 = new Card(4, i); cards.add(card); cards.add(card2); cards.add(card3); cards.add(card4); } } public int size() { int num=cards.size(); return num; }

The final class is the Card class.

public class Card {
private int rank;
private int suit;
public Card(int s, int r)
{
    suit=s;
    rank=r;
}
public int getSuit()
{
    return suit;
}
public int getRank()
{
    return rank;
}

It must be an obvious error due to my lack of understanding so can anyone show what to do to fix it?

java oop

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

OOP course content in C# | OOP in C# Part-1

LIKE | COMMENT | SHARE | SUBSCRIBE OOP(object oriented programming) Course content........ Blog : http://aspdotnetexplorer.blogspot.com Like our page - https...

Basic OOP with Class and Objecct | OOP in C# Part-3

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Class and Object . Blog : http://aspdotnetexplorer.blogspot.com Like our page - h...

Java Core (2020) | Java for beginners | Brush up your Java Skills | Get Hired

In this video we will learn about all the major concepts that come under Java Core . The course is very carefully designed and is made with keeping simplicit...

Java OOPs Tutorial For Beginners | Java Object Oriented Programming

"Java OOPs Tutorial For Beginners | Java Object Oriented Programming | Java OOPs Basics" will give an introduction to Java Object Oriented Programming. Learn how to create and use OOP cocepts. Learn about all the OOP concepts: Abstraction, Encapsulation, Polymorphism, and Inheritance

OOPS Concept In JAVA | Object Oriented Programming | Java For Beginners

OOPs concept in Java tutorial will help you to understand comprehensively all the concepts of OPPs. We will be clearing all your doubts that you may have regarding this topic "OPPS in Java" such as What is Inheritance in Java, What are abstract classes in Java, Interface in Java, and much more along with the clear-set examples for better understanding.