Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

can we create a class inside a class in java

Yes you can

class OuterClass {
   class InnerClass {
   }
}
Comment

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 create a boolean list in java 
Java :: java remove double spaces 
Java :: how to sprint minecraft java 
Java :: calling a method in java 
Java :: string program to calculate number of characters in a string java 
Java :: Spring boot init method 
Java :: start an activity in adapter 
Java :: android get id of view 
Java :: for var i = 0 
Java :: get sum of int array and return string 
Java :: java color light gray 
Java :: Simple Write a simple Java program that prints a staircase or a figure as show 
Java :: devoluciones redsys api 
Sql :: safe mode off mysql 
Sql :: fatal error: libpq-fe.h: No such file or directory 
Sql :: mysql status 
Sql :: identity_insert is set to off 
Sql :: mysql where column not integer 
Sql :: oracle table privileges 
Sql :: display all databases 
Sql :: sql server beginning of month 
Sql :: mysql change database charset and collation 
Sql :: mysql get first x characters 
Sql :: how to stop all connections to a psql 12 database? 
Sql :: mysql first day of month 
Sql :: postgresql print sessions using the database 
Sql :: mysql check table exists 
Sql :: how to remove unique key constraint in mysql 
Sql :: sql padd let with zeros 
Sql :: postgres connection string 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =