Está en la página 1de 3

Student Assignment on Basic Java

The answers for the following questions should be checked by the student himself by making small programs (reflecting the question) on the system. In case of clarifications, student may contact the faculty.

State true or false:


1. !. ". $. %. &. '. *. +. 1,. 11. 1!. 1". 1$. 1%. 1&. 1'. 1*. 1+. !,. !1. !!. !". !$. !%. !&. !'. !*. !+. ",. "1. "!. "". "$. "%. "&. "'. "*. "+. $,. $1. $!. $". $$. $%. A final class can ha e instances. An abstract class can ha e instances. A final class can be e#tended. An abstract class can be e#tended. A final method can be o erridden. A final method can be o erloaded. (asting is necessary to assign a subclass ob)ect to a superclass ob)ect. Assigning a superclass ob)ect to a subclass ob)ect does not need casting. The order in which access modifiers appear before a class or method is important. An interface can be instantiated. An abstract class should ha e at least one abstract method. An interface should ha e at least one abstract method. -a a does not support pointers, but pointers do e#ist inside -a a run.time system. If a class does not e#tend any class, it is defined implicitly as an immediate subclass of class /b)ect. In -a a, a superclass can ha e any number of subclasses. / erloading in ol es inheritance. An o erridden method is two or more methods ha ing the same name in the same class. An o erloaded method should ha e the same method signature including return type. An o erridden method should ha e the same method signature but may ha e any return type. super( ) is used to call superclass methods. (onstructors cannot be nati e, abstract, static, synchroni0ed or final. Abstract classes must be subclassed for functionality. Interfaces must be subclassed for functionality. An interface can be a separate unit and can be compiled into a byte code file. The parameter of a switch statement can be of type int , char , short or long. (ollecti ely, the methods and instance ariables defined in a class are called members. java.lang.Math.Pl returns floating.point alue of data type double. 1y default, if not assigned, instance ariables are set to 0ero and local ariables are set to null. 2e can e#plicitly cast in between all the primiti e data types. Arrays are created at compile.time. In -a a, primiti e data types are passed by alue and ob)ects are passed by reference. The local ariables can not be pri ate, protected or public. finali0e( ) method is called )ust prior to garbage collection. static members of a class can not be pri ate. The bytecode erifier erifies whether the input is in bytecodes or not. The abstract methods in an abstract class can be declared final, if needed. final class can inherit but can not be inherited. An abstract class can ha e a super class. An abstract class can implement an interface, but need not implement all the methods of the interface. An interface can implement another interface. 3tatic methods can not be abstract. 4inal methods can not be abstract. Implemented methods of the interface must be public. Import statement must be the first among package, import and class statements in a class declaration. (onstructors must be declared before any methods in a class.

Student Assignment on Basic Java


In o erriding, superclass static method cannot be called with super keyword. (onstructors may be protected. Interfaces can ha e protected access specifier. Interfaces can e#tend other concrete classes. Interfaces can ha e final ariables. Interface methods can not be static, final, synchroni0ed, nati e, pri ate or protected. An interface method implemented in a subclass can be o erloaded. Interface abstract methods can be o erloaded. An interface can e#tend an abstract class. An abstract class can implement an interface, An abstract class can ha e a main( ) method. pri ate method can be o erridden. static members can be final. An abstract method can throw an 5#ception. 6ocal ariables can not be static. static methods cannot be o erridden. static methods can be o erloaded. static method can be pri ate. All the methods of a final class are implicitly final. A class cannot be both final and abstract. Abstract class can ha e static methods. Interfaces are slow, as it requires e#tra indirection to find corresponding method in the actual class. Abstract classes are fast. &*. 4or both fields and classes, package access is the default, and is used when no access is specified. &+. null is a keyword of -a a. ',. An interface can e#tend two interfaces. Some important statements to remember: All instance ariables and array elements, if not assigned : byte, short, int, long ( including static ) are initiali0ed to ,. float and double are initiali0ed to ,., char is initiali0ed to null and does not display any alue. boolean is initiali0ed with false. ob)ects are initiali0ed to null. reference ariables are initiali0ed to null. $&. $'. $*. $+. %,. %1. %!. %". %$. %%. %&. %'. %*. %+. &,. &1. &!. &". &$. &%. &&. &'.

Wh the constructors cannot be abstract, static, final, native, strictfp, or s nchroni!ed " 7nlike methods, a constructor cannot be abstract, static, final, nati e, strictfp, or synchroni0ed. A constructor is not inherited, so there is no need to declare it final and an abstract constructor could ne er be implemented. A constructor is always in oked with respect to an ob)ect, so it makes no sense for a constructor to be static. There is no practical need for a constructor to be synchroni0ed , because it would lock the ob)ect under construction, which is normally not made a ailable to other threads until all constructors for the ob)ect ha e completed their work. The lack of nati e constructors is an arbitrary language design choice that makes it easy for an implementation of the -a a irtual machine to erify that superclass constructors are always properly in oked during ob)ect creation.

S.Nageswara Assignment Rao, Sr.Facu ty, !onsu tant and !orporate "rainer Student on Basic Java #ncase of doubts, the students may contact the facu ty at surenagrao$yahoo.co.in

Prepared for his students at Peers, Maitrivanam, Ameerpet, Hyd. by

También podría gustarte