Skip to main content

Brain-storming !!!

1. Can we declare and use a private constructor in any class?
2. Can we use return statement between two statements of a method in Java?
3. Can we create the object of a local class in any other class? How?
4. Can we override a static method?
5. How can you find the address of an ArrayList object in Java?

Comments

  1. 1.yes,in case we have two or more overloaded constructors to make object for that class.
    also in case if we dont have only static members n main function is in the same class we can declare its constuctor as private, as we will not need to create its object.
    also we can use inhertance.
    class B
    {
    B()
    {
    System.out.println("B constructor is called");
    }
    }
    class A extends B
    {
    int a;
    private A()
    {
    int a=0;
    System.out.println("A constructor is called");
    }
    public static A fun()
    {
    A obj=new A();
    return obj;
    }
    public void yahoo()
    {
    System.out.println("A method of class A is called");
    }
    }
    public class C
    {
    public static void main(String []args)
    {
    B obj1=A.fun();
    }
    }
    ..
    Although we cannot use others methods .. eg- yahoo() here.
    ...

    ReplyDelete

Post a Comment

Popular posts from this blog

ETE Practice Set-1

                                                                 Mock Test-1 -----------------------------------------------------------------------------------------------------------------------------   1 (a) Write a program that reads 10 integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0.                                                         ...

Practice Set: Unit-4

                                                                                                                Practice Set: Unit 4 1. What are the uses of super keyword in Java? Explain with a suitable example. 2. What are the various uses of final keyword in java? An abstract method can not be declared final. Why? 3. Differentiate between Abstract class and Interface. What do you mean by Functional interface and Lambda Expression?  ...

OLA-UBER Problem

Create two interfaces OLA and UBER both having a method public static Cab getCab() which returns the Cab object where Cab is a nested class inside OLA and UBER. Cab must have attributes cab_number and driver_name. A user rides 5 times using cabs of OLA and UBER randomly which are stored in an array. Now implement a method which should display the name of the driver and the company name i.e. OLA/UBER when the valid cab_number is entered by the user. Display "Invalid CAB details" when the cab_number entered by the user is incorrect.