Class

Question 1
Which of the following is/are true about packages in Java?
1) Every class is part of some package
2) All classes in a file are part of the same package
3)If no package is specified, the classes in the file go into a special unnamed package.
4) If no package is specified, a new package is created with folder name of class and the class is put in this package
A
Only 1,2 and 3
B
Only 1,2 and 4
C
Only 4
D
Only 1 and 3
       OOPS       Class       Nielit Scientist-B IT 22-07-2017
Question 1 Explanation: 
Option -4 false because new package is created by using syntax package package_name which is user defined .There is no relation with class name.
Question 2
Which of the following is false about abstract classes in java?
A
If we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as abstract using 'abstract' keyword
B
Abstract classes can have constructors.
C
A class can be made abstract without any abstract method
D
A class can inherit from multiple abstract classes
       OOPS       Class       Nielit Scientist-B IT 22-07-2017
Question 2 Explanation: 
● An abstract class can have an abstract method without body and it can have methods with implementation also. ● Multiple inheritance is not possible with abstract classes.
Question 3
Which of the following is true about interfaces in java?
1. An interface can contain following type of members.
...public,static,final fields(i.e., constants)
...default and static methods with bodies
2. An instance of interface can be created.
3. A class can implement multiple interfaces
4. many classes can implement the same interface
A
1,3 and 4
B
1,2 and 4
C
2,3 and 4
D
1,2,3 and 4
       OOPS       Class       Nielit Scientist-B IT 22-07-2017
Question 3 Explanation: 
● The interface in java is a blueprint of a class. It has static constants and abstract methods.
● There can be only abstract methods in the Java interface, not method body.
● It cannot be instantiated just like the abstract class because there is no method definition available with the interface.
Question 4
The figure below depicts the hierarchy_____class
A
Heap
B
Wrapper
C
Inheritance
D
Abstract
       OOPS       Class       KVS DEC-2013
Question 4 Explanation: 
All the wrapper classes (Integer, Long, Byte, Double, Float, Short) are subclasses of the abstract class Number.
Question 5
​ To override a method in java, we need to define a method in a subclass with the
A
Same name, same number of arguments having the same data types as a method in the superclass
B
Different name, same number of arguments having the same data types as a method in the superclass
C
Same name but different number of arguments as a method in the superclass
D
Same name, same number of arguments but different data types as a method in the superclass
       OOPS       Class       KVS DEC-2013
Question 5 Explanation: 
●The argument list should be exactly the same as that of the overridden method.
● The return type should be the same or a subtype of the return type declared in the original overridden method in the superclass.
Question 6
Assume the C++ definitions: Class circle: public point which of the following is false?
A
'point' is the base class and 'circle' is the derived class
B
The colon(:) in the header of class definition indicates inheritance
C
The keyword 'public' indicates type of inheritance
D
All the public and protected members of class 'circle' are inherited as public and protected members respectively into class point.
       OOPS       Class       KVS DEC-2017
Question 6 Explanation: 
True: point' is the base class and 'circle' is the derived class
True: The colon(:) in the header of class definition indicates inheritance
True: The keyword 'public' indicates type of inheritance
False: All the public and protected members of class 'circle' are inherited as public and protected members respectively into class point.
Question 7
If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access
A
Protected and public data only in C and B
B
Protected and public data only in C
C
Private data in A and B
D
Protected data in A and B
       OOPS       Class       KVS 30-12-2018 Part B
Question 7 Explanation: 
The following table shows the access to members permitted by each modifier.
Question 8
Members of  class by default are
A
Public
B
Private
C
Protected
D
Mandatory to specify
       OOPS       Class       KVS 30-12-2018 Part B
Question 8 Explanation: 
→A class in C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private).
→The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class.
There are 8 questions to complete.
PHP Code Snippets Powered By : XYZScripts.com
error: Content is protected !!