{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

003 - class Outer public class PublicInner protected class...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: class Outer { public class PublicInner{) protected class ProtectedInner {) private class Privatelnner{) abstract class AbstractInner {J final class Finallnner {) static class StaticInner {} - Each instance of an inner class is associated with an instance of their outer class — Inner classes may not declare static initializes or static members unless they are compile time constants (i.e. static final var = value ;) f‘ — We cannot declare an interface as a member of an inner class, interfaces are never inner - Inner classes may inherit static members - The inner class can access the variables and methods declared in the outer class a- -To refer to a field or method in the outer class instance from within the inner class, use Outer.this.fldname. - If a class inherits outer class, then it can only access the members of the outer ciass but not the members of the inner class. Problem 4: The book (and the Ecture notes!) state that Java has no template mechanism. However Java 5 does. Describe how Java implements parametric polymorphism. I Solution:- Java 5 supports many pre-definaf constructs with parametric polymorphism. For egtample...'consider AmyList construct in java. If you want to create an array list which stores elements of integer type, then we can simply create an AtrayList in the following way: ., ArrayList a1 = new ArrayList <int> ( ); If you want to place an integer in the ArrayList you can simply call add () method. Similarly we can get/the integer from the ArrayList without any typecasting, by calling get () method. The functiqvélities of add () and get () methods remain same for all types of elements. ...
View Full Document

{[ snackBarMessage ]}