QuestionQ175

Java Basics

Given:

Question Image

Which two code fragments can be inserted at line n1?

Choose two
  • A String str = ג€Javaג€;
  • B for(int iVal = 0; iVal <=5; iVal++){}
  • C Test() {}
  • D package p1;
  • E import java.io.*;
Explanation

A class body can contain field declarations and constructor declarations. String str = "Java"; declares a field, and Test() {} declares a constructor. A for statement cannot appear directly in a class body, and package and import declarations must occur outside the class declaration.

Community Discussion

No comments yet. Be the first to start the discussion!