- Start with this code:
public class Newsfeed {
public Newsfeed(){
}
// Create getTopics() below:
public static void main(String[] args){
Newsfeed sampleFeed = new Newsfeed();
/*
String[] topics = sampleFeed.getTopics();
System.out.println(topics);
*/
}
}
-
We have an empty
Newsfeed
class that does not store anything yet.First, make a method called
getTopics()
, which:- is
public
- returns a
String
array - does not take any parameters
For now, leave the method empty.
- is
-
Inside the
getTopics()
method, create aString
array calledtopics
and set it equal to an array containing these elements, in order:Opinion Tech Science Health
Then, return
topics
from the method! -
Uncomment the lines in the main method to see how the
getTopics()
method works on aNewsfeed
instance.
Example solution can be found in the Newsfeed.java file