Core Java - Interview Questions and Answers for 'Sub class' - 3 question(s) found - Order By Newest Q1. What is the difference between inner class and sub class ? Core Java
Ans. Inner Class is a class that is nested within another class whereas sub class is a class that extends or inherit another class.
Inner class can only be accessed using reference of outer class ( Class name , if inner class is static or object reference, if inner class is non static ) whereas Sub class is accessed directly.
In terms of memory, inner class is stored just like another class having it's own body whereas sub class carries the body of parent class as well as it's own fields in memory. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner classes  nested classes  inner class vs sub class  nested class vs sub class Basic Related Questions Which of the following can be marked static ?
a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes Difference between nested and inner classes ? What is a nested interface ? Which of the following cannot be marked static ? Explain use of nested or inner classes ? What is the benefit of inner / nested classes ? Explain Static nested Classes ? Can we have an inner class within Interface ? Upon compiling the following class, What .class files will get created
public class OuterClass{
class InnerClass{
}
}
Q2. Can an inner class be subclass of it's parent class ? Core Java
Ans. Yes that can be done
public class OuterClass {
public class InnerClass extends OuterClass {
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner classes  nested classes  sub class Basic Related Questions Which of the following can be marked static ?
a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes What is the difference between inner class and sub class ? Difference between nested and inner classes ? What is a nested interface ? Which of the following cannot be marked static ? Explain use of nested or inner classes ? What is the benefit of inner / nested classes ? Explain Static nested Classes ? Can we have an inner class within Interface ? Upon compiling the following class, What .class files will get created
public class OuterClass{
class InnerClass{
}
}
Q3. Is this code legal in java i.e nested class within interface implementing the parent interface ?
public interface MyInterface {
public class MyClass implements MyInterface {
}
} Core Java
Ans. Yes that's legal in java Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner classes  nested classes  sub class Basic Related Questions Which of the following can be marked static ?
a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes What is the difference between inner class and sub class ? Difference between nested and inner classes ? What is a nested interface ? Which of the following cannot be marked static ? Explain use of nested or inner classes ? What is the benefit of inner / nested classes ? Explain Static nested Classes ? Can we have an inner class within Interface ? Upon compiling the following class, What .class files will get created
public class OuterClass{
class InnerClass{
}
}