Java Reflection - Attributes
JAVA reflection is a very powerful tool to inspect the attributes of a class in runtime. For example, we can retrieve the list of public fields of a class using getDeclaredMethods(). In this problem, you will be given a class Solution in the editor. You have to fill in the incompleted lines so that it prints all the methods of another class called Student in alphabetical order. We will append your code with the Student class before running it. The Student class looks like this: class Stude
View Solution →Can You Access? Java
You are given a class Solution and an inner class Inner.Private. The main method of class Solution takes an integer num as input. The powerof2 in class Inner.Private checks whether a number is a power of 2. You have to call the method powerof2 of the class Inner.Private from the main method of the class Solution. Constraints 1<=num<=2^30
View Solution →Prime Checker Java
You are given a class Solution and its main method in the editor. Your task is to create a class Prime. The class Prime should contain a single method checkPrime. The locked code in the editor will call the checkPrime method with one or more integer arguments. You should write the checkPrime method in such a way that the code prints only the prime numbers. Please read the code given in the editor carefully. Also please do not use method overloading! Note: You may get a compile time erro
View Solution →Java Factory Pattern
According to Wikipedia, a factory is simply an object that returns another object from some other method call, which is assumed to be "new". In this problem, you are given an interface Food. There are two classes Pizza and Cake which implement the Food interface, and they both contain a method getType(). The main function in the Main class creates an instance of the FoodFactory class. The FoodFactory class contains a method getFood(String) that returns a new instance of Pizza or Cake accor
View Solution →Java Singleton Pattern
"The singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system." - Wikipedia: Singleton Pattern Complete the Singleton class in your editor which contains the following components: 1.A private Singleton non parameterized constructor. 2.A public String instance variable named str. 3.Write a static method named getSingleInstance that returns the single instance o
View Solution →