JAVA Classes and Methods Mcqs
Our collections of Multiple choice questions and answers focuses on study of Java Classes and Methods . These questions are chosen from a collection of most authoritative and best reference books on Java Classes and Methods. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Classes and Methods comprehensively.
- Home
- »
- Languages
- »
- Programming Languages Mcqs
- »
- Java Programming Mcqs
- »
- Java Classes and Methods Mcqs
- »
- Page 3
Java Programming Mcqs
- Data Types Variables and Arrays Mcqs
- Exception Handling in Java Mcqs
- Interfaces and Packages Mcqs
- Java Classes and Methods Mcqs
- Java Event Handling Mcqs
- Java Inheritance Mcqs
- Java IO and Applets Mcqs
- java lang and java io Mcqs
- Java Language Fundamentals Mcqs
- Java Operators and Control Statements Mcqs
- java utilities Mcqs
- Miscellaneous Topics in Java Mcqs
- Multithreading in Java Mcqs
- Serialization and Networking Mcqs
- Session Management and JSP and Servlet Mcqs
- String Handling
Computer MCQS
Sciences MCQS
34.
What is the output of the following code?
class Compscibits
{
public void m1 (int i,float f)
{
System.out.println(" int float method");
}
public void m1(float f,int i);
{
System.out.println("float int method");
}
public static void main(String[]args)
{
Compscibits c=new Compscibits();
c.m1(20,20);
}
}
class Compscibits
{
public void m1 (int i,float f)
{
System.out.println(" int float method");
}
public void m1(float f,int i);
{
System.out.println("float int method");
}
public static void main(String[]args)
{
Compscibits c=new Compscibits();
c.m1(20,20);
}
}
Int float method
Float int method
Compile time error
Run time error
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
35.
What is the output of this program?
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a, int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}
}
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a, int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}
}
5
6
7
8
36.
What is the output of this program?
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a , int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6, 7);
System.out.println(obj.x);
}
}
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a , int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6, 7);
System.out.println(obj.x);
}
}
6
7
8
9
37.
Which of these is used to access a member of class before object of that class is created?
Public
Private
Static
Protected
38.
Which of these is used as a default for a member of a class if no access specifier is used for it?
Private
Public
Public, within its own package
Protected
39.
Which of the following statements are incorrect?
Public members of class can be accessed by any code in the program
Private members of class can only be accessed by other members of the class
Private members of class can be inherited by a subclass, and become protected members in subclass
Protected members of a class can be inherited by a subclass, and become private members of the subclass
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
40.
What is the output of this program?
class access
{
public int x;
private int y;
void cal(int a, int b)
{
x = a + 1;
y = b;
}
}
class access_specifier
{
public static void main(String args[])
{
access obj = new access();
obj.cal(2, 3);
System.out.println(obj.x + " " + obj.y);
}
}
class access
{
public int x;
private int y;
void cal(int a, int b)
{
x = a + 1;
y = b;
}
}
class access_specifier
{
public static void main(String args[])
{
access obj = new access();
obj.cal(2, 3);
System.out.println(obj.x + " " + obj.y);
}
}
3 3
2 3
Runtime Error
Compilation Error
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
41.
What is the output of this program?
class access
{
public int x;
private int y;
void cal(int a, int b)
{
x = a + 1;
y = b;
}
void print()
{
system.out.println(" " + y);
}
}
class access_specifier
{
public static void main(String args[])
{
access obj = new access();
obj.cal(2, 3);
System.out.println(obj.x);
obj.print();
}
}
class access
{
public int x;
private int y;
void cal(int a, int b)
{
x = a + 1;
y = b;
}
void print()
{
system.out.println(" " + y);
}
}
class access_specifier
{
public static void main(String args[])
{
access obj = new access();
obj.cal(2, 3);
System.out.println(obj.x);
obj.print();
}
}
2 3
3 3
Runtime Error
Compilation Error
42.
Which one of the following is not an access modifier?
Public
Private
Protected
Void
43.
All the variables of class should be ideally declared as?
Private
Public
Protected
Default
44.
Which of the following modifier means a particular variable cannot be accessed within the package?
Private
Public
Protected
Default
45.
How can a protected modifier be accessed?
Accessible only within the class
Accessible only within package
Accessible within package and outside the package but through inheritance only
Accessible by all
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
46.
What happens if constructor of class A is made private?
Any class can instantiate objects of class A
Objects of class A can be instantiated only within the class where it is declared
Inherited class can instantiate objects of class A
Classes within the same package as class A can instantiate objects of class A
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
47.
All the variables of interface should be?
Default and final
Default and static
Public, static and final
Protect, static and final
Answer & Solution
No Solution for this Answer..! Report or Discus this Question