Thread: Telephonic Round Interview Question

Forum : Job discussions   11-8-2016 12:00:00 AM
User Image
Basanta2041

Newbie

Joined: Apr 20, 2017

Points: 100

Threads: 27

Posts: 139

Telephonic Round Interview Question

| Quote Date : Aug 11, 2016    Views:2071    

[code] Telephonic Round Question : 1.As we know we cannot instantiate Abstract class then why there is no restriction for taking constructor in Abstract class 2.what is the difference between concrete class in 1.7 and interface in 1.8 In both cases we can take method main method all those things 3.What is Marker interface, can we create our own markup interface if yes then how jvm will know about your custom markup interface 4.how can I create Custom Arraylist. 5.how many way we can create Immutable class brief it with step [|code]

tags: java

Comments

User Image
sreenuu

Newbie

Joined : Jul 27, 2017

Points : 100

Threads: 0

Posts: 1

Re: Telephonic Round Interview Question

Reply Date : Aug 9, 2017

Thanks for sharing

User Image
Divya254

Newbie

Joined : Jul 4, 2017

Points : 100

Threads: 0

Posts: 2

Re: Telephonic Round Interview Question

Reply Date : Aug 9, 2017

Thank you for sharing the information

User Image
Rajeev1711

Newbie

Joined : Jun 26, 2017

Points : 115

Threads: 9

Posts: 11

Re: Telephonic Round Interview Question

Reply Date : Aug 9, 2017

if we can not instantiate abstract class why we write a constructors in it?

As we know constructors are meant to initialize the fields but not to create an object. objects are created by "new" keyword (correct me if i'm wrong). Here is my observation

public abstract class AbsTest
{
int a;
int b;

public AbsTest(int a,int b){
this.a=a;
this.b=b;
}
}

class AbsTestImpl extends AbsTest
{
static  int a=10;
    static int b=20;

public void method(int a, int b){}
   
   AbsTestImpl(){
      super(a,b);
  }

public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

Here AbsTest class fields are assigned value by its childclasses. So, as per our requirements we can instantiate abstract class fields by our values. I also see if you either you have to pass the direct values to the super class or the fields that you are passing to super class should be static. if you write your child class as:
 
class AbsTestImpl extends AbsTest
{
  int a=10;
  int b=20;

public void method(int a, int b){}
   
   AbsTestImpl(){
      super(a,b);
  }

public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

it will give you compile time error: "can not reference a before supertype constructor has been called;  can not reference b before supertype constructor has been called;?"   which you have to explore why?
Good question bro.keep posting such questions, it's really helpful.





User Image
Rajeev1711

Newbie

Joined : Jun 26, 2017

Points : 115

Threads: 9

Posts: 11

Re: Telephonic Round Interview Question

Reply Date : Aug 9, 2017

if we can not instantiate abstract class why we write a constructors in it?

As we know constructors are meant to initialize the fields but not to create an object. objects are created by "new" keyword (correct me if i'm wrong). Here is my observation

public abstract class AbsTest
{
int a;
int b;

public AbsTest(int a,int b){
this.a=a;
this.b=b;
}
}

class AbsTestImpl extends AbsTest
{
static  int a=10;
    static int b=20;

public void method(int a, int b){}
   
   AbsTestImpl(){
      super(a,b);
  }

public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

Here AbsTest class fields are assigned value by its childclasses. So, as per our requirements we can instantiate abstract class fields. I also see if you either you have to pass the direct values to the super class or the fields that you are passing to super class should be static. if you write your child class as:
 
class AbsTestImpl extends AbsTest
{
  int a=10;
  int b=20;

public void method(int a, int b){}
   
   AbsTestImpl(){
      super(a,b);
  }

public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

it will give you compile time error: "can not reference a before supertype constructor has been called;  can not reference b before supertype constructor has been called;?"   which you have to explore why?
Good question bro.keep on posting such questions, it's really helpful.





Load More

No More Comments