Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java call method from another class example

public class method{
  public static void sayHello(){
    System.out.println("Hello World");
  }
}
public class app{
  public static void main(String[] args){
    method m = new method(); // Creating an instance from our class
    m.sayHello(); // using the class methods by the instance we created.
  }
}
Comment

how to access methods from another class in java

public class Alpha extends Beta{
     public void DoSomethingAlpha() {
          DoSomethingBeta();  //?
     }
}
Comment

Calling A Class From Another Class In Java

class ClassComposition
{
    public static void main(String arg[])
    {
        Room hall = new Room("Hall"); // LINE A
        hall.area = 200.0;
        hall.paintColor = "Voilet";
        hall.flooring = "Marble";
        
        hall.ceilingFan = new Fan("Bajaj"); // LINE B
        hall.ceilingFan.speed = 500;     // LINE B1
        hall.ceilingFan.numberOfSpeeds = 5;
        
        hall.tube = new Light("Hall tube light"); // LINE C
        hall.tube.color = "White";
        hall.tube.watts = 40;
        hall.tube.tube = true;    // LINE C1
        
        Light bl = new Light("Yellow bed light"); // LINE D
        hall.bedLight = bl;
        hall.bedLight.color = "Yellow";
        hall.bedLight.watts = 50;
        hall.bedLight.tube = false;
        
        System.out.println("Hall fan speed : " + hall.ceilingFan.speed);
        System.out.println("Bed Light color : " + hall.bedLight.color);    
    }
}

class Fan
{
    String name;
    double speed;
    String color;
    int numberOfSpeeds;

    Fan(String name)
    {
        this.name = name;
    }
}

class Light
{
    String name;
    String color;
    int watts;
    boolean tube;

    Light(String name)
    {
        this.name = name;
    }
}

class Room
{
    String name;
    double area;
    String paintColor;
    String flooring;
    Fan ceilingFan;
    Light tube;
    Light bedLight;

    Room(String name)
    {
        this.name = name;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to delete last array in java 
Java :: final class java 
Java :: find repeated elements in array java 
Java :: Calculate weeks from date using java 
Java :: alert dialog not displayed android 
Java :: java @override 
Java :: java stream group by multiple fields 
Java :: search in 2d matrix 
Java :: number of digits program in java 
Java :: Java Lambda Expressions with parameters 
Java :: biginteger modulo in java 
Java :: for var i = 0 
Java :: devotional meaning 
Java :: android cella 20*20 java 
Java :: how apache shiro remember me works 
Sql :: sql developer search all packages for text 
Sql :: count of tables in database mysql 
Sql :: cannot truncate a table referenced in a foreign key constraint 
Sql :: how to get yesterday date in sql 
Sql :: Enter into postgresql database,create user and grant Access 
Sql :: mysql workbench in ubuntu 14.04 
Sql :: too many connections mysql 
Sql :: mysql group by month 
Sql :: show list of users in mysql 
Sql :: get schema of table sql 
Sql :: alter foreign key 
Sql :: convert varchar to int in sqlite 
Sql :: no data found oracle 
Sql :: rename table postgres 
Sql :: CREATE DATABASE db; SyntaxError: Unexpected identifier 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =