Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

can we create a class inside a class in java

Yes you can

class OuterClass {
   class InnerClass {
   }
}
Comment

java class creation inside method

public class ASimplisticTCPFiniteStateMachine_FSM_ {
    public static void main(String[] args) {
        class Lmao_It_Exists {
            public void main() {
                System.out.println("Hello World");
            }
        }
        new Lmao_It_Exists().main();
    }
}
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 use Runnable interface to develop multi-threaded Java programs? 
Java :: java convert float to int 
Java :: date format android 
Java :: convert int[] to list java 
Java :: declare hashmap java 
Java :: java return list 
Java :: how to send get request in java 
Java :: javafx tableview add data 
Java :: how to check whether a character is alphabet or not in java 
Java :: string to hexstring In java 
Java :: sqlexception 
Java :: regex pattern for date validation 
Java :: how to get key value from json object in java 
Java :: java max int value 
Java :: Validation failed for query for method public abstract java.util.List 
Java :: convert int to ascii java 
Java :: check self permission android write_external_storage 
Java :: on touch listener android 
Java :: multiple type array java 
Java :: java download 64-bit 
Java :: java convert java.util.Date to LocalDate 
Java :: java responseentity 
Java :: fileinputstream 
Java :: loop through an arraylist android studio 
Java :: compare two character alphabetically java 
Java :: java nested loop 
Java :: Send image file to server useing Retrofit 
Java :: java convert date to localdate 
Java :: how to return array in java 
Java :: find minimum in array java 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =